仅当复选框勾选闪亮的应用程序R时,才会下拉菜单

时间:2016-06-21 08:55:01

标签: r checkbox drop-down-menu shiny

我有一个闪亮的复选框和一个selectInput下拉菜单。

如果勾选了复选框,则会显示一个图表,显示从下拉菜单中选择的相关数据。

如果取消选中该复选框,则下拉菜单仍然可见,但图表未显示。

我如何更改它以便在勾选方框之前实际显示下拉菜单?

到目前为止我的代码示例是这样的:

ui <- fluidPage(checkboxInput(inputId = "compare",label="Load new plot?",value=F),
                dateInput(inputId = "lowerlimit", label="Lower Date",value="2016-01-01"),
                dateInput(inputId = "upperlimit",label="Upper Date"),
                selectInput(inputId = "data2",label="Choose data source", choices="FILEPATHS"),
                plotOutput("plot",dblclick = "plot_dblclick", brush = brushOpts(id="plot_brush",resetOnNew = T)))

server <- function(input,output,session){

  autoInvalidate <- reactiveTimer(300000, session) #new

  ranges <- reactiveValues(x = NULL, y = NULL)

  output$plot <- renderPlot({
    autoInvalidate() # Load new data every 5 minutes if available.
    if(input$compare==T){
      data2=read.csv(paste0("FILEPATH",input$data2,".csv"))

      if (!is.null(ranges$x)) {
        ggplot(data2, aes(Date, Data, group=1))+geom_line()+
          scale_x_datetime(limits=c(ranges$x), labels = date_format("%d-%m-%y %H:%M"))
      } else {
        ggplot(data2, aes(Date, Data, group=1))+geom_line()+
          scale_x_datetime(limits=c(as.POSIXct(input$lowerlimit), as.POSIXct(input$upperlimit)), labels = date_format("%d-%m-%y %H:%M"))
      }
    }
  })

  observeEvent(input$plot_dblclick, {
    brush <- input$plot_brush
    if (!is.null(brush)) {
      ranges$x <- c(brush$xmin, brush$xmax)
      ranges$y <- c(brush$ymin, brush$ymax)

    } else {
      ranges$x <- NULL
      ranges$y <- NULL
    }
  })

}

shinyApp(ui=ui, server=server)

1 个答案:

答案 0 :(得分:1)

应该工作

conditionalPanel("input.compare",
selectInput(inputId = "data2",label="Choose data source", choices="FILEPATHS"))