Skip to content

Instantly share code, notes, and snippets.

@ijlyttle
Created August 14, 2013 20:57
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 ijlyttle/6235528 to your computer and use it in GitHub Desktop.
Save ijlyttle/6235528 to your computer and use it in GitHub Desktop.
coding all elements by hand
library(shiny)
items <- c("seed")
shinyServer(function(input, output) {
add_item_a <- reactive({
# register button
n_click <- input$item_add_a_go
if (n_click > 0){
new_item <- isolate(input$item_add_a)
items <<- c(items, new_item)
}
return()
})
add_item_b <- reactive({
# register button
n_click <- input$item_add_b_go
if (n_click > 0){
new_item <- isolate(input$item_add_b)
items <<- c(items, new_item)
}
return()
})
get_items <- reactive({
# register "adders"
add_item_a()
add_item_b()
return(items)
})
output$show_items <- renderPrint(get_items())
})
library(shiny)
shinyUI(pageWithSidebar(
# Application title
headerPanel("Test of reactivity"),
sidebarPanel(
# add item & go button
textInput(inputId="item_add_a", label="Add an item here", value=""),
actionButton(inputId="item_add_a_go", label="Go!"),
# add item
textInput(inputId="item_add_b", label="Or, add an item here", value=""),
actionButton(inputId="item_add_b_go", label="Go!")
),
mainPanel(
verbatimTextOutput(outputId="show_items")
)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment