Created
October 10, 2015 20:43
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>') | |
}) | |
} | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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