leafletProxy not working
MaddeeRubenson opened this issue · comments
Maddee Rubenson commented
leafletProxy doesn't seem to be functional within shinyDashboard. See working example below where choosing different letters should change the circle color. Any insight appreciated.
library(shiny)
library(shinydashboard)
library(leaflet)
library(sf)
n = 100
df1 = data.frame(id = 1:n,
x = rnorm(n, 10, 3),
y = rnorm(n, 49, 1.8))
pts = st_as_sf(df1, coords = c("x", "y"), crs = 4326)
map <- leaflet() %>%
addProviderTiles(provider = providers$CartoDB.DarkMatter) %>%
addCircles(data = pts, group = "pts") %>%
setView(lng = 10.5, lat = 49.5, zoom = 6)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
selectInput(inputId = 'click', 'Choose one:', c('A', 'B', 'C'))
),
dashboardBody(
fluidRow(
div(
id = "map",
column(
width = 12,
leafletOutput('map', height = '800px')),
)
)
)
)
server <- function(input, output) {
output$map <- renderLeaflet({map})
observeEvent(input$click, {
col <- switch(input$click,
'A' = 'green',
'B' = 'yellow',
'C' = 'white')
m <- leafletProxy("map") %>%
clearShapes() %>%
addCircles(data = pts,
color = col)
m
})
}
shinyApp(ui, server)
ismirsehregal commented
For future readers - I posted an answer here. (The problems are not shinydashboard
related)
Maddee Rubenson commented
Thanks for your help, @ismirsehregal