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

Feature Request: replaceData #49

Closed
uriahf opened this issue Jun 3, 2020 · 6 comments
Closed

Feature Request: replaceData #49

uriahf opened this issue Jun 3, 2020 · 6 comments

Comments

@uriahf
Copy link

uriahf commented Jun 3, 2020

Hi, first of all a great package! Thank you for your time and effort!

Is it possible to make a function like replaceData in DT?
https://rdrr.io/cran/DT/man/replaceData.html

I'd like to update my table without regenerating it every time I change the inputs.

@glin
Copy link
Owner

glin commented Jun 6, 2020

Hi,

Yup this is possible, and something I started working on a while back. It'll be added through something like updateReactable(data = newData), most likely for the next release. Thanks for the feature request!

@uriahf
Copy link
Author

uriahf commented Jun 6, 2020

It sounds great!
Honestly, that's the only reason why I don't use reactable in most cases yet. By the way, the update for crosstalk is extremely important for me!

Ideally, I would like to make a proxy table with other nested proxy tables inside. Unfortunately it doesn't seem possible with DT, maybe it will be possible with reactable in the future?

@glin
Copy link
Owner

glin commented Jun 15, 2020

Added a data argument to update data via updateReactable(): https://glin.github.io/reactable/reference/updateReactable.html. When updating data, the selection, expansion, and current page state will reset by default, but all other state (e.g. sorting, filtering) should persist.

The updateReactable() example app uses this to implement custom data filtering: https://glin.github.io/reactable/articles/examples.html#update-a-reactable-instance

And here's another toy app that simulates real-time data updates: https://github.com/glin/reactable/blob/master/inst/examples/shiny-data-streaming.R

@glin
Copy link
Owner

glin commented Jun 15, 2020

Nested proxy tables should already be supported, but it's definitely not well tested. You may stumble upon some bugs :). To use updateReactable() with a nested table, you'll have to render the nested table as a Shiny output, like:

reactable(
  details = function(index) {
    reactableOutput("nested_table")
  }
)

Here's an example app that uses updateReactable() with a nested table.

library(shiny)
library(reactable)

data <- MASS::Cars93[, 1:7]

ui <- fluidPage(
  selectInput("filter_type", "Filter type", unique(data$Type), multiple = TRUE),
  reactableOutput("table")
)

server <- function(input, output) {
  output$table <- renderReactable({
    reactable(
      data,
      defaultExpanded = TRUE,
      details = function(index) {
        if (index == 2) {
          reactableOutput("nested_table")
        }
      }
    )
  })
  
  output$nested_table <- renderReactable({
    reactable(data, selection = "multiple", bordered = TRUE)
  })
  
  observeEvent(input$filter_type, {
    if (length(input$filter_type) > 0) {
      filtered <- data[data$Type %in% input$filter_type, ]
    } else {
      filtered <- data
    }
    updateReactable("nested_table", data = filtered)
  }, ignoreNULL = FALSE)
}

shinyApp(ui, server)

@glin glin closed this as completed Jun 15, 2020
@uriahf
Copy link
Author

uriahf commented Jun 17, 2020

This is awesome!
Thank you so much!

@lemuelemos
Copy link

Added a data argument to update data via updateReactable(): https://glin.github.io/reactable/reference/updateReactable.html. When updating data, the selection, expansion, and current page state will reset by default, but all other state (e.g. sorting, filtering) should persist.

The updateReactable() example app uses this to implement custom data filtering: https://glin.github.io/reactable/articles/examples.html#update-a-reactable-instance

And here's another toy app that simulates real-time data updates: https://github.com/glin/reactable/blob/master/inst/examples/shiny-data-streaming.R

It's possible to update and not reset expansion?

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

No branches or pull requests

3 participants