Skip to content

Instantly share code, notes, and snippets.

@statwonk
Created October 10, 2015 20:43
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 statwonk/7444a60c8f15fe4e80b5 to your computer and use it in GitHub Desktop.
Save statwonk/7444a60c8f15fe4e80b5 to your computer and use it in GitHub Desktop.
An example of passing a json blob to the front-end from a Shiny app back-end.
library(shiny)
iris <- datasets::iris
names(iris) <- gsub('[/.]','_',tolower(names(iris)))
shinyServer(
function(input, output) {
output$json <- reactive({
paste('<script>data=',
RJSONIO::toJSON(iris[iris$species == input$species,], byrow=T, colNames=T),
';console.log(data[0]);', # print 1 data line to console
'</script>')
})
}
)
require(shiny)
iris <- datasets::iris
names(iris) <- gsub('[/.]','_',tolower(names(iris)))
specs <- as.character(unique(iris$species))
names(specs) <- specs
pageWithSidebar(
headerPanel("minimal json handling example"),
sidebarPanel(selectInput("species", "Species", specs)),
mainPanel(
htmlOutput("json")
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment