reactive change min/max range + 2 dataframes Shiny

前端 未结 1 882
一生所求
一生所求 2021-01-07 15:34

I have one problem with my Shiny app. Firstly, I have two dataframes in which there are two numeric columns ( number and number2

相关标签:
1条回答
  • 2021-01-07 15:56

    As you realize, you are getting the error because the filtered dataset has no rows. A simple workaround would be to return the full dataset. This will reset the inputSlider for you to continue working without error. You only need to change your reactive data function.

    data <- reactive({
      filteredData <- datasetInput()
      axisData <- axis_vara_y()
    
      if(!is.null(input$inslider)){
        filteredData <- filteredData %>%
          filter(filteredData[,axisData] >= input$inslider[1],
                 filteredData[,axisData] <= input$inslider[2])
      }
    
      # the new part to reset the slider
      if(nrow(filteredData) == 0){
        return(datasetInput())
      }else{
        return(filteredData)
      }
    })
    

    I have taken the liberty of simplifying the code a little bit as you can assign your reactive data statements and not have the shiny app call them several times.

    0 讨论(0)
提交回复
热议问题