【问题标题】:Slider in renderui not workingrenderui中的滑块不起作用
【发布时间】: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


    【解决方案1】:

    我实际上有一个“提交按钮”,它阻止了其他事件的发生。问题解决了!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-06
      • 2017-10-13
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      • 1970-01-01
      • 2013-07-21
      相关资源
      最近更新 更多