knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) library(gior)
gior
lets you catch which country is selected and which is related to the latter very easily. Just use the id
of your gior
visualisation with followed by:
_selected
to get data related to the selected country._related
to get data related to the selected country.Run the example below to see both of the above demonstrated or hit the button below to visit the live demo.
library(DT) library(gior) library(shiny) ui <- fluidPage( fluidRow( column( 10, h3("Map"), giorOutput("gior") ), column( 2, h3("Selected"), verbatimTextOutput("sel") ) ), fluidRow( column( 12, h3("Related countries"), DTOutput("rel") ) ) ) server <- function(input, output, session) { data("country_data") output$gior <- renderGior({ country_data %>% gior() %>%ยง g_data(from, to, value) }) output$sel <- renderPrint({ input$gior_selected }) output$rel <- renderDT({ DT::datatable(input$gior_related) }) } shinyApp(ui, server)
gior
comes with numerous proxies. Shiny proxies let you interact with a visualisation without having to redraw it everytime you do so.
For examples, you can change the dataset on the fly without having to redraw the entire globe.
library(shiny) data("country_data") ui <- fluidPage( actionButton("add", "add"), actionButton("clear", "clear"), uiOutput("sw"), giorOutput("gior") ) server <- function(input, output, session){ output$sw <- renderUI({ selectInput("selectCountry", "Switch Country", choices = unique(country_data$from)) }) observeEvent(input$selectCountry, { giorProxy("gior") %>% g_switch_p(input$selectCountry) }) output$gior <- renderGior({ country_data %>% gior() %>% g_data(from, to, value) }) observeEvent(input$clear, { giorProxy("gior") %>% g_clear_p() }) observeEvent(input$add, { giorProxy("gior") %>% g_data_p(country_data, from, to, value) }) } shinyApp(ui, server)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.