Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Demo to show widget types, return values and data types in Shiny
##########################################
##### data types and values - server.R ###
##########################################
library(shiny)
shinyServer(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
})
})
##############################
### data Types - ui.R ########
##############################
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("Widget values and data types"),
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 commented Jun 21, 2014

thanks

Good, thanks.

Appreciation for your 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.

bouasr commented Jun 7, 2017

Thanks...

Super helpful. Thanks

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