Skip to content

Instantly share code, notes, and snippets.

@cecilialee
Last active February 10, 2018 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cecilialee/3999fb45275d19c4f883b221754e045a to your computer and use it in GitHub Desktop.
Save cecilialee/3999fb45275d19c4f883b221754e045a to your computer and use it in GitHub Desktop.
Access inputs and output values in Shiny. #r #shiny
# Using double brackets
## Understanding inputs and outputs as a list. Their values are accessable via double brackets.
library(shiny)
ui = basicPage(
textInput("txt", "Text"),
textOutput("ptxt")
)
server = function(input, output) {
output[["ptxt"]] <- renderText({ input[["txt"]] })
}
shinyApp(ui, server)
# Using dollar sign
## Most convenient usage. However, there'll be situations when this is not useful.
library(shiny)
ui = basicPage(
textInput("txt", "Text"),
textOutput("ptxt")
)
server = function(input, output) {
output$ptxt <- renderText({ input$txt })
}
shinyApp(ui, server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment