rara2
November 6, 2018, 12:35am
1
Hello,
I was wondering if someone could help me with this issue. I have a dataframe I've created after reading a CSV. I am using renderDataTable to display the table. Users can come on the Rshiny app and filter the data table by inputting selections from drop down menus. Is it possible to save and download the filtered data-table as a CSV? I have gotten it to download, however, never post filtration.
-rara2
1 Like
hi @rara2 , yes that should be possible. Do you get an error?
It would be great if you could post a reprex (short for minimal repr oducible ex ample).
Right now the best way to install reprex is:
# install.packages("devtools")
devtools::install_github("tidyverse/reprex")
If you've never heard of a reprex before, you might want to start by reading the tidyverse.org help page . The reprex dos and don'ts are also useful.
For pointers specific to the community site, check out the reprex FAQ, linked to below.
Why reprex?
Getting unstuck is hard. Your first step here is usually to create a reprex, or reproducible example. The goal of a reprex is to package your code, and information about your problem so that others can run it and feel your pain. Then, hopefully, folks can more easily provide a solution.
What's in a Reproducible Example?
Parts of a reproducible example:
background information - Describe what you are trying to do. What have you already done?
complete set up - include any library() calls and data to reproduce your issue.
data for a reprex: Here's a discussion on setting up data for a reprex
make it run - include the minimal code required to reproduce your error on the data…
1 Like
Yes, you can easily add the download option to you shiny application with downloadButton()
or downloadLink()
functions.
Here it is an example:
# In server.R:
filtered_data <- reactive({
filter(raw_data, Column1==input$value)})
output$downloadData <- downloadHandler(
filename = function() {
paste('data-', Sys.Date(), '.csv', sep='')
},
content = function(con) {
write.csv(filtered_data(), con)
}
)
# In ui.R:
downloadLink('downloadData', 'Download')
You can access more details in function web page at https://shiny.rstudio.com/reference/shiny/1.0.4/downloadButton.html .
2 Likes