Skip to content

Instantly share code, notes, and snippets.

@ChrisBeeley
Last active October 2, 2019 15:55
Show Gist options
  • Save ChrisBeeley/6571951 to your computer and use it in GitHub Desktop.
Save ChrisBeeley/6571951 to your computer and use it in GitHub Desktop.
Demo to show widget types, return values and data types in Shiny
function(input, output) {
output$textDisplay <- renderTable({
getMat = matrix(
c(paste(input$checkGroup, collapse=','), class(input$checkGroup),
input$boxInput, class(input$boxInput),
as.character(as.Date(input$theDate, origin = "1970-01-01")), class(input$theDate),
paste(as.character(as.Date(input$dateRange[[1]], origin = "1970-01-01")),
as.character(as.Date(input$dateRange[[2]], origin = "1970-01-01")),
collapse = ','),
class(input$dateRange),
input$pickNumber, class(input$pickNumber),
input$pickRadio, class(input$pickRadio),
input$comboBox, class(input$comboBox),
input$slider, class(input$slider),
input$comment, class(input$comment)
), ncol = 2, byrow = TRUE)
colnames(getMat) = c("Value", "Class")
getMat
})
}
fluidPage(
titlePanel("Widget values and data types"),
sidebarLayout(
sidebarPanel(
checkboxGroupInput(inputId = "checkGroup",
label = "1. checkboxGroupInput",
choices = list("Ice cream" = "IC", "Trifle" = "Trifle",
"Pistachios" = "Pist")),
checkboxInput(inputId = "boxInput",
label = "2. checkboxInput"),
dateInput(inputId = "theDate",
label = "3. dateInput"),
dateRangeInput(inputId = "dateRange",
label = "4. dateRangeInput"),
numericInput(inputId = "pickNumber",
label = "5. numericInput",
min = 1, max = 10, value = 1),
radioButtons(inputId = "pickRadio",
label = "6. radioButtons",
choices = list("Taxi" = "Taxi", "Take a walk" = "Walk")),
selectInput(inputId = "comboBox",
label = "7. selectInput",
choices = list("News" = "News", "Situation comedy" = "Sitcom", "Film" = "Film")),
sliderInput(inputId = "slider",
label = "8. sliderInput",
min = 1, max = 10, value = 7, step = 1),
textInput(inputId = "comment",
label = "9. textInput",
value = "")
),
mainPanel(
h3("Output and data type"),
tableOutput("textDisplay")
)
)
)
@rhamza
Copy link

rhamza commented Jun 21, 2014

thanks

@bluepill5
Copy link

Good, thanks.

@whizzalan
Copy link

Appreciation for your link.

@romunov
Copy link

romunov commented Jul 26, 2015

I made a crossbreed app between what you have and widget gallery on rstudio's website. Mainly because I was pissed at how implicit the docs are about how to access values input by user without making a reproducible example for every widget added.

@Bouba-BF
Copy link

Bouba-BF commented Jun 7, 2017

Thanks...

@tamirbennatan
Copy link

Super helpful. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment