Created
January 26, 2016 17:33
-
-
Save vpnagraj/f0432c9cd3f77ff90b1d to your computer and use it in GitHub Desktop.
trivial shiny app with file download handler
This file contains hidden or 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) | |
library(dplyr) | |
server <- function(input, output) { | |
output$downloadData <- downloadHandler( | |
filename = function() { | |
paste('data_', Sys.Date(), '.csv', sep='') | |
}, | |
content = function(file) { | |
mtcars %>% | |
filter(am == input$trans) %>% | |
group_by(Cylinder = factor(cyl)) %>% | |
summarise(Mean.HP = mean(hp)) %>% | |
write.csv(file, row.names = FALSE) | |
} | |
) | |
output$dattable <- DT::renderDataTable( | |
mtcars %>% | |
filter(am == input$trans) %>% | |
group_by(Cylinder = factor(cyl)) %>% | |
summarise(Mean.HP = mean(hp)) | |
) | |
} | |
ui <- fluidPage( | |
sidebarLayout( | |
sidebarPanel( | |
selectInput("trans", "Transmission", choices = c(0,1)) | |
), | |
mainPanel( | |
downloadButton("downloadData", "Download Your 'Clean' Data"), | |
DT::dataTableOutput("dattable") | |
) | |
) | |
) | |
shinyApp(ui = ui, server = server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment