Last active
September 27, 2015 08:40
-
-
Save explodecomputer/0bb9efb98b0a5e431a8f to your computer and use it in GitHub Desktop.
shiny app example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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