In my brilliant application, I have two tabs: tab 1 has checkboxInput and selectInput, which is encoded as renderUI on the .R server and is displayed only if the checkbox is selected. On tab 2, there is a ggvis function for constructing a data frame that is created using a reactive function only if selectInput was shown on tab 1.
Unexpectedly, selectInput does not appear on tab 1 unless I first click on tab 2 and then go back to tab 1, even if selectInput depends only on the checkbox located on the same tab, i.e. tab 1.
Apparently, I do not understand the idea of reactive functions. Could you please indicate where is my mistake? Thank!
PS The structure is quite complicated, but this is what I need for my "real" application.
ui.R
library(ggvis)
shinyUI(navbarPage("",
tabPanel("1",
checkboxInput("START", label = "Start calculations", value = F),
htmlOutput("SELECT")
),
tabPanel("2",
ggvisOutput("PLOT")
)
))
server.R
library(ggvis)
shinyServer(function(input, output, session) {
output$SELECT<-renderUI({
if (input$START==T) {
selectInput("SELECTINPUT","Make your choice:",c(1,2))
}
})
PLOTDF<-reactive({
if (is.null(input$SELECTINPUT)==F) {
plotdf<-data.frame(c(1,1,2,2),c(1,2,3,4))
colnames(plotdf)<-c("X","Y")
plotdf
}
})
reactive({
PLOTDF() %>% ggvis(~X,~Y) %>% layer_points
}) %>% bind_shiny("PLOT")
})