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

Issue using replaceData() with dataTableProxy() #1101

Closed
gadenbuie opened this issue Nov 28, 2023 · 4 comments
Closed

Issue using replaceData() with dataTableProxy() #1101

gadenbuie opened this issue Nov 28, 2023 · 4 comments

Comments

@gadenbuie
Copy link
Member

gadenbuie commented Nov 28, 2023

AFAICT, this issue was introduced in #1096. We found this in the nightly shiny tests, which started to fail the day after the day #1096 was merged (and then it took me a little bit to triage and track down the issue).

Here's a small reprex app:

library(shiny)
library(DT)

ui <- fluidPage(
  DTOutput("table"),
  actionButton("inc", "Increment")
)

server <- function(input, output, session) {
  x <- reactiveVal(0L)

  df <- reactive({
    data.frame(value = x())
  })

  output$table <- renderDT({
    DT::datatable(
      isolate(df()),
      rownames = FALSE,
      options = list(dom = "t", ordering = FALSE)
    )
  })

  observeEvent(input$inc, {
    message("incrementing x: ", x(), " -> ", x() + 1L)
    x(x() + 1L)
  }, ignoreNULL = TRUE)

  observeEvent(x(), {
    req(x() > 0)
    message("replacing table data")
    replaceData(dataTableProxy("table"), df())
  })
}


shinyApp(ui, server)

The expected behavior is for the table to be a single column (value) with a single row. When clicking on the Increment button, the value should increment by one, using replaceData(dataTableProxy("table"), df()).

The current behavior I'm seeing is that the app starts as expected

image

but then after clicking the increment button to update the data, the table shows no rows.

image

@stla
Copy link
Collaborator

stla commented Nov 29, 2023

It works if we set rownames=FALSE:

replaceData(dataTableProxy("table"), df(), rownames = FALSE)

@yihui
Copy link
Member

yihui commented Nov 29, 2023

Right, if the original table was rendered with rownames = FALSE, the new data should also use rownames = FALSE when replacing the old data.

I've tested CRAN releases 0.30 and 0.29. The problem doesn't seem to be new, i.e., both CRAN versions can reproduce the problem. I don't know why it didn't happen before...

@yihui
Copy link
Member

yihui commented Dec 7, 2023

@gadenbuie Could you check if rownames = FALSE works? Thanks!

@gadenbuie
Copy link
Member Author

@yihui it resolves the issue in the reprex! It didn't resolve the new issue in our test apps, but I realized the test app used replaceData(dataTableProxy("table"), x()) (replacing the table with a value, not a data frame), so maybe that was unintentionally supported until recently. Anyway, I've updated our test app with both fixes and I think we can consider this resolved. Thanks all!

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