glin / reactable

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

JavaScript API: more docs on integration into Shiny apps #282

Closed nick-youngblut closed 1 year ago

nick-youngblut commented 1 year ago

I'm new to reactable, and as I new user, I've found the examples for the JavaScript API not too clear/helpful for using the API in a Shiny. For instance, it's unclear from the csv-download-button example how to integrate that code correctly into a Shiny app. More examples of integrating the JavaScript API into Shiny apps would be appreciated.

glin commented 1 year ago

Thanks for the feedback, I'll look into getting at least one Shiny + JavaScript API example in somewhere. Part of the reason there's no Shiny app example is that the JavaScript API was created to do things outside of Shiny (e.g., you can already do download buttons in Shiny using the built-in downloadButton). So I didn't really expect the JavaScript API to be used in Shiny, but there are now definitely some use cases for it. For example, custom filter inputs, or a CSV download button that knows about the client-side filtered state.

For now, the only docs for using the JavaScript API with Shiny would be the Using the JavaScript API section, which doesn't show a full example. I'll probably add an example of using the CSV download button in Shiny, like:

library(shiny)
library(htmltools)

data <- MASS::Cars93[, c("Manufacturer", "Model", "Type", "Price")]

ui <- fluidPage(
  tags$button(
    tagList(shiny::icon("download"), "Download as CSV"),
    onclick = "Reactable.downloadDataCSV('cars_table', 'cars.csv')"
  ),
  reactableOutput("cars_table")
)

server <- function(input, output) {
  output$cars_table <- renderReactable({
    reactable(
      data,
      searchable = TRUE
    )
  })
}

shinyApp(ui, server)
nick-youngblut commented 1 year ago

The example that you show above is helpful. Thanks!

glin commented 1 year ago

Now added to the docs at CSV download button in Shiny, and there will likely be other JavaScript API + Shiny examples in the future.