Created
March 21, 2013 16:59
-
-
Save wch/5214648 to your computer and use it in GitHub Desktop.
renderImage example for Shiny
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
shinyServer(function(input, output, clientData) { | |
output$myImage <- renderImage({ | |
# A temp file to save the output. | |
# This file will be removed later by renderImage | |
outfile <- tempfile(fileext='.png') | |
# Generate the PNG | |
png(outfile, width=400, height=300) | |
hist(rnorm(input$obs), main="Generated in renderImage()") | |
dev.off() | |
# Return a list containing the filename | |
list(src = outfile, | |
contentType = 'image/png', | |
width = 400, | |
height = 300, | |
alt = "This is alternate text") | |
}, deleteFile = TRUE) | |
}) |
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
shinyUI(pageWithSidebar( | |
headerPanel("renderImage example"), | |
sidebarPanel( | |
sliderInput("obs", "Number of observations:", | |
min = 0, max = 1000, value = 500) | |
), | |
mainPanel( | |
imageOutput("myImage") | |
) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment