Skip to content

Instantly share code, notes, and snippets.

@jeffreyhorner
Created December 6, 2012 03:48
Show Gist options
  • Save jeffreyhorner/4221630 to your computer and use it in GitHub Desktop.
Save jeffreyhorner/4221630 to your computer and use it in GitHub Desktop.
simpleTab with visible tab id
library(shiny)
shinyServer(function(input, output) {
cat('shinyServer called\n',file=stderr())
output$foo <- reactivePrint(function(){
cat('output$foo called\n',file=stderr())
input
})
runIfVisible <- function(visibleTab,val,expr){
if (visibleTab==val)
return(eval(expr,parent.frame()))
else
return(NULL)
}
output$afunc <- reactivePrint(function() {
runIfVisible(input$visibleTab,'A',{
cat('output$afunc updated\n',file=stderr())
input$n
})
})
output$bfunc <- reactivePrint(function() {
runIfVisible(input$visibleTab,'B',{
cat('output$bfunc updated\n',file=stderr())
Sys.sleep(4)
input$n
})
})
output$plot <- reactivePlot(function(){
runIfVisible(input$visibleTab,'Plot',{
cat('output$plot updated\n',file=stderr())
plot(rnorm(input$n))
})
})
})
library(shiny)
shinyUI(pageWithSidebar(
# Application title
headerPanel("Tabsets"),
sidebarPanel(
sliderInput("n",
"Number of observations:",
value = 500,
min = 1,
max = 1000)
),
mainPanel(
tabsetPanel(
tabPanel("A", verbatimTextOutput("afunc")),
tabPanel("B", verbatimTextOutput("bfunc")),
tabPanel("Plot",plotOutput('plot')),
id='visibleTab'
)
)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment