Skip to content

Instantly share code, notes, and snippets.

@jcheng5
Last active January 3, 2016 09:19
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/8441665 to your computer and use it in GitHub Desktop.
Save jcheng5/8441665 to your computer and use it in GitHub Desktop.
library(shiny)
library(datasets)
shinyServer(function(input, output) {
## Inputs;
output$uitextInput <- renderUI({
textInput("caption", "Caption:", "Data Summary")
})
output$uiselectInput <- renderUI({
selectInput("dataset", "Choose a dataset:",
choices = c("rock", "pressure", "cars"))
})
output$uinumericInput <- renderUI({
numericInput("obs", "Number of observations to view:", 10)
})
datasetInput <- reactive({
switch(input$dataset,
"rock" = rock,
"pressure" = pressure,
"cars" = cars)
})
output$caption <- renderText({
input$caption
})
output$summary <- renderPrint({
dataset <- datasetInput()
summary(dataset)
})
output$view <- renderTable({
head(datasetInput(), n = input$obs)
})
})
library(shiny)
shinyUI(bootstrapPage(
tagList(
tags$head(
tags$script(type="text/javascript", src = "inputTracking.js")
)
),
div(class = "span4",
uiOutput("uitextInput"),
uiOutput("uiselectInput"),
uiOutput("uinumericInput")
),
div(class = "span8",
h3(textOutput("caption")),
verbatimTextOutput("summary"),
tableOutput("view")
)
))
$(document).on("change", "input.shiny-bound-input, select.shiny-bound-input", function(e){
var $target = $(e.target);
if ($target.attr("type") === "checkbox") {
alert(e.target.checked);
}
else {
alert($target.val());
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment