Reputation: 1866
I have a checkbox in shiny, and a selectInput
drop down menu.
If the checkbox is ticked, then a plot will display showing the relevant data selected from the drop down menu.
If the checkbox is un-ticked, then the drop down menu is still visible, but the plot does not show.
How would I change it so that the drop down menu doesn't actually appear until the box is ticked?
An example of my code so far is something like this:
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)
Upvotes: 1
Views: 1544
Reputation: 5779
Should Work
conditionalPanel("input.compare",
selectInput(inputId = "data2",label="Choose data source", choices="FILEPATHS"))
Upvotes: 2