【发布时间】:2017-02-11 16:32:15
【问题描述】:
我有一个闪亮的应用程序:
- 从带有一些要点的传单开始
- 允许用户使用 fileInput 加载 CSV
- 使用 LeafletProxy 在地图上绘制 CSV
- 动态添加滑块以过滤来自新 CSV 的值
我的问题是滑块对地图没有任何影响。它显示正常,但是当我移动它时,observe 和observeevent 都没有效果。
我的代码的相关部分是
# Create a new map with the data uploaded
observe({
if (is.null(newdata())) return(NULL)
# Update the map
leafletProxy("map", data = newdata()) %>%
clearMarkers() %>%
addCircles(newdata()$Y,
newdata()$X,
color = "red")
# Add a slider
datecol <- newdata()$Date
output$setSlider <- renderUI({
if (is.null(newdata())) return(NULL)
sliderInput("range", "Dates",
min = as.Date(min(datecol)),
max = as.Date(max(datecol)),#,"%Y-%m-%d"
value = c(as.Date(min(datecol)),as.Date(max(datecol))),
timeFormat="%Y-%m-%d")
})
})
# Filter the data
dataloc <- reactive({
print(input$range)
filteredData <- newdata()
if(!is.null(input$range)){
filteredData <- filteredData %>%
filter(filteredData$Date >= input$range[1],
filteredData$Date <= input$range[2])
}
return(filteredData)
})
observeEvent(input$range,{
filterloc <- dataloc()
print("event")
if (is.null(newdata())) return(NULL)
if (!is.null(dataloc())) return(print(dataloc()))
# Update the map
leafletProxy("map", data = dataloc()) %>%
clearMarkers() %>%
addCircles(dataloc()$Y,
dataloc()$X,
color = "red")
}
)
滑块出现后不会出现print("event")。
【问题讨论】:
标签: shiny