Skip to content

Instantly share code, notes, and snippets.

@explodecomputer
Last active September 27, 2015 08:40
Show Gist options
  • Save explodecomputer/0bb9efb98b0a5e431a8f to your computer and use it in GitHub Desktop.
Save explodecomputer/0bb9efb98b0a5e431a8f to your computer and use it in GitHub Desktop.
shiny app example
shinyApp(
ui = navbarPage(title="test", id="mainNavbarPage",
tabPanel("Input", value="tabinput",
numericInput('n', 'Number of obs', 100),
actionButton(inputId="submit_button", label="Submit")
),
tabPanel("Output", value="taboutput",
verbatimTextOutput("messages"),
plotOutput('plot')
)
),
server = function(input, output, session) {
messages <- ""
observeEvent(input$submit_button, {
# Move to results page first
updateNavbarPage(session, "mainNavbarPage", selected="taboutput")
messages <- paste(messages, "Welcome to the app!\n")
# Tell user what is happening
output$messages <- renderPrint({
cat(messages)
})
# Perform lots of calculations that may take some time
messages <- paste(messages, "Sleeping for no reason...\n")
output$messages <- renderPrint({
cat(messages)
})
Sys.sleep(5)
messages <- paste(messages, "Creating plot...\n")
output$messages <- renderPrint({
cat(messages)
})
output$plot <- renderPlot({ hist(runif(input$n)) })
messages <- paste(messages, "Complete!\n")
output$messages <- renderPrint({
cat(messages)
})
})
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment