我使用了两个watchEvents, 一个在selectInput上,另一个在map_shape_click上。
map_shape_click更新selectInput上的值。
如何避免在map_shape_click之后触发selectinput值, 在仅更改selectInput的同时保持触发器?
请参见下面的代码。单击折线时,将触发下拉事件。如何避免这种情况?
library(leaflet)
ui <- fluidPage(
mainPanel(
leafletOutput("mymap"),
p(),
selectInput("test", "test", c("value 1", "value 2", "value 3", "X")),
p(),
textOutput("selected_var")
)
)
df <- data.frame (lat = c(41.82, 46.88, 41.48, 39.14), lon = c(-88.32, -124.10, -88.33, -114.90))
server <- shinyServer (function(input, output, session) {
output$mymap <- renderLeaflet({
leaflet('map',height = "100%") %>% addTiles()
})
observe({
leafletProxy('mymap') %>% addPolylines(data = df, lat = ~lat, lng = ~lon, layerId="test", group = "test")
})
observeEvent(input$mymap_shape_click,{
print ("shapeclicked")
output$selected_var <-renderText ("shapeclicked")
updateSelectInput(session, "test", selected = "X")
})
observeEvent(input$test, {
print ("dropdown triggered")
output$selected_var <-renderText ("dropdown triggered")
})
})
shinyApp(ui = ui, server = server)