leaflet
leaflet copied to clipboard
addMinichart ERROR, response to UI ERROR
Hello I used the exaple data of quakes, I want to draw PIE plot, I modify the script, but get the error report. Your help will be more useful for me, thankyou CODE: library(shiny) library(leaflet) library(RColorBrewer)
ui <- bootstrapPage( tags$style(type = "text/css", "html, body {width:100%;height:100%}"), leafletOutput("map", width = "100%", height = "100%"), absolutePanel(top = 10, right = 10, sliderInput("range", "Magnitudes", min(quakes$mag), max(quakes$mag), value = range(quakes$mag), step = 0.1 ), selectInput("colors", "Color Scheme", rownames(subset(brewer.pal.info, category %in% c("seq", "div"))) ), checkboxInput("legend", "Show legend", TRUE) ) )
server <- function(input, output, session) {
Reactive expression for the data subsetted to what the user selected
filteredData <- reactive({ quakes[quakes$mag >= input$range[1] & quakes$mag <= input$range[2],] }) filteredData
This reactive expression represents the palette function,
which changes as the user makes selections in UI.
colorpal <- reactive({ colorNumeric(input$colors, quakes$mag) })
output$map <- renderLeaflet({ # Use leaflet() here, and only include aspects of the map that # won't need to change dynamically (at least, not unless the # entire map is being torn down and recreated). leaflet(quakes) %>% addTiles() %>% fitBounds(~min(long), ~min(lat), ~max(long), ~max(lat)) })
Incremental changes to the map (in this case, replacing the
circles when a new color is chosen) should be performed in
an observer. Each independent set of things that can change
should be managed in its own observer.
observe({ pal <- colorpal()
leafletProxy("map", data = filteredData()) %>%
clearShapes() %>%
##MY MODIFY HERE addMinicharts(lng=~long, lat=~lat,chartdata=~[c("mag","mag")]) ) })
Use a separate observer to recreate the legend as needed.
observe({ proxy <- leafletProxy("map", data = quakes)
# Remove any existing legend, and only if the legend is
# enabled, create a new one.
proxy %>% clearControls()
if (input$legend) {
pal <- colorpal()
proxy %>% addLegend(position = "bottomright",
pal = pal, values = ~mag
)
}
}) }
shinyApp(ui, server)
ERROR: Warning: Error in leafletProxy: leafletProxy must be called from the server function of a Shiny app [No stack trace available] I think it didnot active to the UI. Thankyou!