在renderui的滑块不工作

时间:2017-02-10 13:58:01

标签: shiny

我有一个闪亮的应用程序:

  • 以传单开头,上面有一些点
  • 允许用户使用fileInput
  • 加载CSV
  • 使用LeafletProxy
  • 在地图上绘制CSV
  • 动态添加滑块以过滤新CSV
  • 中的值

我的问题是滑块对地图没有任何影响。它显示很好,但是当我移动它时,观察或观察事件都没有效果。

我的代码的相关部分是

  # 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")不会发生。

1 个答案:

答案 0 :(得分:0)

我实际上有一个&#34; submitButton&#34;这阻止了其他事件的发生。问题解决了!

相关问题