Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export buttons #11

Closed
fmmattioni opened this issue Nov 19, 2019 · 14 comments
Closed

Export buttons #11

fmmattioni opened this issue Nov 19, 2019 · 14 comments
Labels
enhancement New feature or request

Comments

@fmmattioni
Copy link

Fantastic package! Is it possible to have export buttons as {DT} does?

https://rstudio.github.io/DT/extensions.html#buttons

@dktanwar
Copy link

Yes, I agree. It would be great to have the export buttons as well.

@BenWoods
Copy link

I agree. This appears to be the only feature missing from DT that I regular use.

@glin
Copy link
Owner

glin commented Nov 22, 2019

Agreed it'd be useful as well. React Table doesn't support this out of the box, but it wouldn't too difficult to implement. Or at least provide a way to add custom buttons with access to the table instance/data, so users could do whatever they want (exporting, copying, etc.).

@fmmattioni
Copy link
Author

Looking forward to it! I will update some of my shiny apps from {DT} to {reactable} once this is available.. I really love some of the functionalities here

@aiccu
Copy link

aiccu commented Nov 27, 2019

Amazing work on this package! And like @fmmattioni, I plan on migrating most of my dashboards over once this is aligned.

@DiegoConde
Copy link

Congratulations on this package. It´s amazing. I am migrating all my DT to reactable. When would it be possible to have the buttons to export the data? Thank you and congratulations for this work.

@fmmattioni
Copy link
Author

@DiegoConde take a look at the package I created that you can easily implement download buttons in your rmarkdown :)
https://github.com/fmmattioni/downloadthis

@ssamberkar
Copy link

@DiegoConde take a look at the package I created that you can easily implement download buttons in your rmarkdown :)
https://github.com/fmmattioni/downloadthis

Thanks a lot, reactable and 'downloadthis' are awesome together, crosstalk just sweetens the recipe. Is it possible to save the filtered instance of a table by linking it to an Export button? Or is too difficult to implement?

@mihirp161
Copy link

This feature would be nice too. I have recently moved away from DT package to this one because I no longer have to depend on StaackOverflow to get all my CSS working. Thanks for making this package.

@glin
Copy link
Owner

glin commented Nov 8, 2021

This is now possible to do in the development version (0.2.3.9000) using the new JavaScript API:

  • New JavaScript API to manipulate or access tables from JavaScript. Use this to create custom interactive controls, such as CSV download buttons, custom filter inputs, or toggle buttons for row grouping and row expansion (#11, #28, #182, #194). Learn more in the JavaScript API guide or the JavaScript API examples.

There's no built-in export button, but instead, a Reactable.downloadDataCSV() JavaScript function that downloads the data to CSV and handles the messy details behind the scenes.

You can use this to implement your own CSV download button and style it however you want. The most basic download button could be one line of code:

library(reactable)
library(htmltools)

htmltools::browsable(
  tagList(
    tags$button("Download as CSV", onclick = "Reactable.downloadDataCSV('cars-table', 'cars.csv')"),

    reactable(MASS::Cars93[, 1:5], elementId = "cars-table")
  )
)

Or if you wanted to reuse this download button in other tables, you could write a function for it:

library(reactable)
library(htmltools)

csvDownloadButton <- function(tableId, label = "Download as CSV", filename = "data.csv") {
  htmltools::tags$button(
    label,
    onclick = sprintf("Reactable.downloadDataCSV('%s', '%s')", tableId, filename)
  )
}

htmltools::browsable(
  tagList(
    csvDownloadButton("cars-table", "Download as CSV", filename = "cars.csv"),

    reactable(MASS::Cars93[, 1:5], elementId = "cars-table")
  )
)

For a working demo, check out the CSV download button example in the docs.

For more details on how to use the JavaScript API, check out the the JavaScript API guide and reference.

And for more details on using the Reactable.downloadDataCSV() function, check out the reference for Reactable.downloadDataCSV(). Right now, it's pretty limited in what it does, and just downloads the filtered dataset with sorting/grouping excluded and hidden columns included. However, future enhancements could include options to ignore filtering, exclude headers, exclude hidden columns, apply sorting, or even download to a different format. If you have any ideas to improve it, feel free to leave a comment or open a new issue.

@glin glin closed this as completed Nov 8, 2021
@algo-se
Copy link

algo-se commented Nov 8, 2021

huuuuge! awesome work @glin

@dsolito
Copy link

dsolito commented Feb 2, 2022

Hello,
It's not working for me. Copying the CSV download button example and nothing happens.
Just this message in the console :
ncaught ReferenceError: Reactable is not defined at HTMLButtonElement.onclick (index.html:15:67) onclick @ index.html:15

@xanderwallace85
Copy link

Hello, It's not working for me. Copying the CSV download button example and nothing happens. Just this message in the console : ncaught ReferenceError: Reactable is not defined at HTMLButtonElement.onclick (index.html:15:67) onclick @ index.html:15

Hi @dsolito! I am facing the same issue. Have you found a solution for that?

@glin
Copy link
Owner

glin commented May 2, 2022

@dsolito @xanderwallace85 Do you have the latest development version (v0.2.3.9000) installed from GitHub? The version on CRAN (v0.2.3) doesn't have this feature yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests