Created
December 2, 2014 17:12
-
-
Save geotheory/3ed9e160472d4b330710 to your computer and use it in GitHub Desktop.
Shiny PDF output problem
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) | |
library(ggplot2) | |
shinyServer(function(input, output) { | |
datasetInput <- reactive({ | |
switch(input$dataset, | |
"rock" = rock, | |
"pressure" = pressure, | |
"cars" = cars) | |
}) | |
plotInput <- reactive({ | |
df <- datasetInput() | |
plot(df[[1]], df[[2]]) | |
}) | |
output$plot <- renderPlot({ | |
print(plotInput()) | |
}) | |
output$downloadPlot <- downloadHandler( | |
filename = function() { paste(input$dataset, '.pdf', sep='') }, | |
content = function(file) { | |
pdf(file, width=8, height=6) | |
plotInput() | |
dev.off() | |
}) | |
}) |
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('Downloading Data'), | |
sidebarPanel( | |
selectInput("dataset", "Choose a dataset:", | |
choices = c("rock", "pressure", "cars")), | |
downloadButton('downloadPlot', 'Download Plot') | |
), | |
mainPanel( | |
plotOutput('plot') | |
) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment