glin / reactable

Interactive data tables for R
https://glin.github.io/reactable
Other
627 stars 80 forks source link

Is it possible to download reactable as csv? #182

Closed rdatasculptor closed 2 years ago

rdatasculptor commented 3 years ago

For a project I work on it is sometimes needed to be able to download the table and work on it in more details in e.g. excel. Is it somehow possible to export a reactable as plain text file, such as csv?

Many thanks in advance!

lukr90 commented 3 years ago

What kind of environment do you have your reactable in? For example, in a Shiny app you can add a shiny::downloadHandler() that allows the user to download the same data (also reactive) that goes into the table.

rdatasculptor commented 3 years ago

it's a standalone webpage. For now I solved it by adding a hyperlink to a csv file. But I was just wondering if there was a possibility within reactable.

glin commented 3 years ago

For standalone pages, a hyperlink to the raw data is a great solution. I use hyperlinks to raw data in all the reactable demos, like Twitter Followers: https://github.com/glin/reactable/blob/43bde0593aa4a167b727af02a4f76bf3d82b2d91/vignettes/twitter-followers/twitter-followers.Rmd#L88

For Shiny apps, shiny::downloadHandler() works well and provides more control over the download, as @lukr90 mentions.

For something like a download button that exports table data with filters and sorting applied, that's not possible today, but it is an open feature request (https://github.com/glin/reactable/issues/11). The table data is available through custom JS render/style functions (via state.sortedData), but just isn't easily accessible from outside the table yet.

glin commented 2 years ago

This is now possible to do from a standalone web page using the new JavaScript API in the development version (0.2.3.9000). A hyperlink to the raw data is still a great solution IMO, but you can use a CSV download button if the hyperlink isn't possible, or if you want users to be able to download a filtered dataset. See https://github.com/glin/reactable/issues/11#issuecomment-962809291 for more details and examples.