以下是我的代码:
library(shiny)
library(leaflet)
ui <- fluidPage(
checkboxGroupInput(
inputId = "selected_dates",
label = "Choose the year",
choices = c("20","19","18","17","16","15"),
selected = c("20","19","18","17","16","15")
),
actionButton("go", "Update"),
leafletOutput("map")
)
server <- function(input, output) {
dates <- eventReactive(input$go, {
input$years
})
output$map <- renderLeaflet({
m <- addTiles(setView(leaflet(), lng = -73.731368, lat = 45.531368, zoom = 10))
addCircles(m, data = vol_voiture[vol_voiture$Year %in% input$years,], lat = ~ LATITUDE, lng = ~ LONGITUDE, popup = ~ DATE, opacity = 0.5, weight = 0.1)
})
}
shinyApp(ui, server)
只是澄清一下,vol_voiture
是我的dataframe。我知道这可能只是一个简单的错误或我的部分的误解,但我已经为此工作了很多小时,似乎找不到解决方案。非常感谢您的帮助!
您没有在任何地方使用eventReactive
函数。我会尝试将renderLeaflet调用中的input$years
替换为dates()
library(shiny)
library(leaflet)
ui <- fluidPage(
checkboxGroupInput(
inputId = "selected_dates",
label = "Choose the year",
choices = c("20","19","18","17","16","15"),
selected = c("20","19","18","17","16","15")
),
actionButton("go", "Update"),
leafletOutput("map")
)
server <- function(input, output) {
dates <- eventReactive(input$go, {
input$years
})
output$map <- renderLeaflet({
m <- addTiles(setView(leaflet(), lng = -73.731368, lat = 45.531368, zoom = 10))
addCircles(m, data = vol_voiture[vol_voiture$Year %in% dates(),], lat = ~ LATITUDE, lng = ~ LONGITUDE, popup = ~ DATE, opacity = 0.5, weight = 0.1)
})
}
shinyApp(ui, server)
希望这能有所帮助!!