Appsilon / reactable.extras

Extra features for reactable package
https://appsilon.github.io/reactable.extras/
38 stars 4 forks source link

[Bug]: Sorting table crashes an app when using server side rendering on a reactive dataset #57

Open calderonsamuel opened 3 months ago

calderonsamuel commented 3 months ago

Guidelines

Project Version

0.2.0

Platform and OS Version

I tested in windows and linux

Existing Issues

No response

What happened?

For context: I have to use a reactive dataset for a project. Since reactable_extras_server() is meant to receive a dataframe, I have to put it inside an observer.

However, once the reactive dataset gets modified and I try to sort a column, my app crashes.

Steps to reproduce

library(shiny)
library(reactable)
library(reactable.extras)

ui <- fluidPage(
  selectInput("dataset", "Choose:", c("mtcars", "iris"), "mtcars"),
  reactable_extras_ui("test")
)

server <- function(input, output, server) {

  dataset <- reactive({
    if (input$dataset =="mtcars") mtcars else iris
  })

  observe({
    reactable_extras_server(
      "test",
      data = dataset(),
      total_pages = ceiling(nrow(dataset())/10)
    )
  }) |> 
    bindEvent(dataset())
}

shinyApp(ui, server)

Two ways to break:

  1. Run code snippet. Starts with mtcars.

  2. You can sort by any column (only for the current page, but that is a different problem)

  3. Select the "iris" dataset. Crash

  4. Run code snippet. Starts with mtcars.

  5. Select the "iris" dataset.

  6. Try to sort the table by the "Sepal.Length" column (or any column). Crash ...

Expected behavior

I expect to be able to sort the table without breaking the app

Attachments

This is the error message in the console

Warning: Error in dplyr::arrange: ℹ In argument: `..1 = Sepal.Length`.
Caused by error:
  ! object 'Sepal.Length' not found
64: <Anonymous>
  63: signalCondition
62: signal_abort
61: abort
60: h
59: .handleSimpleError
58: eval
57: mask$eval_all_mutate
56: mutate_col
54: mutate_cols
53: mutate.data.frame
51: arrange_rows
50: arrange.data.frame
48: sort_table
45: ::
  shiny
observe
44: <observer>
  1: runApp

Screenshots or Videos

  1. Run code snippet. Starts with mtcars.
  2. You can sort by any column (only for the current page, but that is a different problem)
  3. Select the "iris" dataset. Crash

https://github.com/Appsilon/reactable.extras/assets/19418298/4012d09d-4018-4ec4-9c26-3538948c5e9b

  1. Run code snippet. Starts with mtcars.
  2. Select the "iris" dataset.
  3. Try to sort the table by the "Sepal.Length" column (or any column). Crash

https://github.com/Appsilon/reactable.extras/assets/19418298/db5e4870-9c81-4bec-ae52-5e89c070e48b

Additional Information

No response