Skip to content

Instantly share code, notes, and snippets.

@vpnagraj
Created January 26, 2016 17:33
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 vpnagraj/f0432c9cd3f77ff90b1d to your computer and use it in GitHub Desktop.
Save vpnagraj/f0432c9cd3f77ff90b1d to your computer and use it in GitHub Desktop.
trivial shiny app with file download handler
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