2016-06-21 132 views
0

下拉菜单我有一个闪亮的复选框,和selectInput下拉菜单。只有当复选框勾选闪亮的应用程序R

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

如果复选框未勾选,则下拉菜单仍然可见,但不显示该图。

我该如何改变它,以便下拉菜单直到勾选框时才真正出现?

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

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

你要么使用'conditionalPanels'或动态创建使用'uiOutput'下拉 –

回答

1

应该工作

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