glin / reactable

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

Unable to make Reactable.setFilter() and Reactable.downloadDataCSV() work #228

Closed tklammsteiner closed 2 years ago

tklammsteiner commented 2 years ago

Dear all,

I've been trying to include the option to filter and download the reactable as CSV file. However, it seems like the elementId variable is not recognized by the two functions Reactable.setFilter() and Reactable.downloadDataCSV(), resulting in a table that can neither be filtered nor downloaded.

Maybe somebody has an idea on how to solve this?

link to the data used tp construct the table from the code below.

library(reactable)
library(htmltools)
library(fontawesome)

metadata <- read.csv("data/metadata.csv", sep = ";")

htmltools::browsable(
   tagList(
     div(
      div(tags$label("Sequencing target", `for` = "target-filter")),
      tags$select(
        id = "target-filter",
        onchange = "Reactable.setFilter('metadata-table', 'Target', this.value)",
        tags$option("All", value = ""),
        lapply(unique(metadata$Target), tags$option)
      )
    ),
    tags$hr("aria-hidden" = "false"),
    tags$button("Download as CSV", onclick = "Reactable.downloadDataCSV('metadata-table', 'metadata.csv')"),

    reactable(
      metadata,
      elementId = "metadata-table",
      highlight = T,
      selection = "multiple",
      borderless = T,
      defaultPageSize = 25,
      resizable = T,
      searchable = T,
      compact = T,
      wrap = F,
      showPageSizeOptions = T,
      pageSizeOptions = c(25, 50, 100),
      columns = list(
        SampleID = colDef(
          style = list(position = "sticky", left = 0, background = "#f7f7f7", zIndex = 1, borderRight = "1px solid #eee"),
          headerStyle = list(position = "sticky", left = 0, background = "#f7f7f7", zIndex = 1, borderRight = "1px solid #eee")
          )
        ),
      theme = reactableTheme(
        rowSelectedStyle = list(backgroundColor = "#eee", boxShadow = "#f7f7f7")
        ),
      )
    )
  )
glin commented 2 years ago

Hi, the filtering and CSV downloading in that code works for me when I run it. What version of reactable do you have installed? These features were only added in a recent development version, so a recent installation from GitHub is required.

If you have a recent install from GitHub, do any errors appear in the browser developer tools console when you filter or click the download button?

tklammsteiner commented 2 years ago

Hi Greg, the version was indeed the problem. I also tried the browser developer tools console but couldn't manage to find my mistake. I had v.0.2.3 installed and after upgrading to v.0.2.3.9000 it works perfectly! Thanks for pointing this out so quickly.