Skip to content

Instantly share code, notes, and snippets.

@jcheng5
Forked from tcash21/server.R
Created August 14, 2013 06:53
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 jcheng5/6228596 to your computer and use it in GitHub Desktop.
Save jcheng5/6228596 to your computer and use it in GitHub Desktop.
require(shiny)
require(rCharts)
inputChoices <- c("A", "B", "C", "D")
shinyServer(function(input, output, session){
input2Choices <- reactive({
inputChoices[-grep(input$input1, inputChoices)]
})
output$input1 <- renderUI({
selectInput("input1", "Input 1:", choices=as.list(inputChoices))
})
output$input2 <- renderUI({
if(is.null(input$input1))
return()
selectInput("input2", "Input 2:", choices=input2Choices())
})
output$show <- renderPrint({
if(is.null(input$input1))
return()
print(carrierInput1())
})
output$show2 <- renderPrint({
print(carrierInput2())
Sys.sleep(2)
})
carrierInput1 <- reactive({
switch(input$input1,
"A" = 1,
"B" = 2,
"C" = 3,
"D" = 4)
})
carrierInput2 <- reactive({
switch(input$input2,
"A" = 1,
"B" = 2,
"C" = 3,
"D" = 4)
})
})
require(shiny)
require(rCharts)
shinyUI(pageWithSidebar(
headerPanel("Dynamic UI inputs with Shiny"),
sidebarPanel(
uiOutput('input1'),
uiOutput('input2')
),
mainPanel(
verbatimTextOutput("show"),
verbatimTextOutput("show2")
)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment