rte-antares-rpackage / leaflet.minicharts

Minicharts for dynamic leaflet maps

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

minichart non-reactive (time)

antoine4ucsd opened this issue · comments

Hi
great package!
I followed your tutorials:
https://cran.r-project.org/web/packages/leaflet.minicharts/vignettes/introduction.html
and here
https://francoisguillem.shinyapps.io/shiny-demo/

with my data, it works just fine with this code:

leaf_map2 %>%
        addMinicharts(
                coordinates_list_all$Longitude, coordinates_list_all$Latitude,
                type = "pie",
                chartdata = coordinates_list_all[, c("VOC50", "VOC90")],
                # colorPalette = colors,
                width = 60 * sqrt(coordinates_list_all$total_cases) / sqrt(max(coordinates_list_all$total_cases)), 
                time = coordinates_list_all$date,
        )
 

but when I try to use within shiny app, the minichart are not updating (the panel looks fine)

 
server = function(input, output, session) {
        # Initialize map
        #
        
        output$map <- renderLeaflet({
                leaf_map2%>% leaflet::addTiles(tilesURL)%>%
                        addMinicharts(
                                coordinates_list_all$Longitude, coordinates_list_all$Latitude,
                                layerId = coordinates_list_all$location,
                                width = 45, height = 45,
                        )
        })
       
        # Update charts each time input value changes
        observe({
                if (length(input$prods) == 0) {
                        data <- 1
                } else {
                        data <- coordinates_list_all[, input$prods]
                }
                maxValue <- max(as.matrix(data))
               
                leafletProxy("map", session) %>%
                        updateMinicharts(
                                coordinates_list_all$location,
                                chartdata = data,
                                maxValues = maxValue,
                                time = coordinates_list_all$date,
                                type = ifelse(length(input$prods) < 2, "polar-area", input$type),
                                showLabels = input$labels
                        )
        })
}
 
ui <- fluidPage(
        titlePanel("COVID-19 Clinical data"),
        p("This application uses the data xxxx COVID-19.",
          "It contains the quarterly data on total cases, VOC 50%, VOC 75% and  VOC 90% from 2020 to 2023."),
       
        sidebarLayout(
               
                sidebarPanel(
                        selectInput("prods", "Select data", choices = dataCols, multiple = TRUE),
                        selectInput("type", "Chart type", choices = c("bar","pie", "polar-area", "polar-radius")),
                        checkboxInput("labels", "Show values")
                ),
               
                mainPanel(
                        leafletOutput("map")
                )
               
        )
)
shinyApp(ui, server)

my data look like that (for now I included same value for the different VOC but won’t be the case after) with prods being total_cases, VOC50, VOC75 and VOC90. the problem seems to be around the time component (nothing change when I click on 'play')

did I miss something here?

Screen Shot 2023-05-03 at 8 16 02 AM

thank you for your help!