Multiple sessions in shiny app resets the previous datatable

Multiple sessions in shiny app resets the previous datatable

oriol8oriol8 Posts: 1Questions: 1Answers: 0
edited April 2023 in Free community support

Hello, Im trying to use a datatable in two or more synchronized sessions whitin a shiny app, but as soon as the second table renders in the second session, the values of the first datatable in the first session restores to 0 and it becomes useless. Im using my datatable to input data so all the values input in the first session goes to 0 as soon as the second instance of the datatable gets rendered on the 2nd browser or session.

output[[unique_id]] <- renderDataTable(server = TRUE, future = FALSE,{
      datatable(
        session$userData[[paste0("catching_tables_", session_id)]]$play_table_catching(),
          rownames = FALSE,
          selection = "none",
          escape = FALSE,
          class = DT:::DT2BSClass(c('compact', 'cell-border')),
          # callback = htmlwidgets::JS(
          #   "$('table.dataTable.no-footer').css('border-bottom', 'none');"
          # ),
          options = list(
            pageLength = 50,
            columnDefs = list(
              list(width = '300px', targets = "_all"),
              list(className = 'dt-center', targets = 0:11),
              list(visible = FALSE, targets = c(0, 1, 2, 3, 4))
            ),
            dom = 'r',
            ordering = FALSE,
            rowCallback = htmlwidgets::JS("function(r,d) {$(r).attr('height', '10px')}"),
            preDrawCallback=JS(
              'function() {
                         Shiny.unbindAll(this.api().table().node());}'),
            drawCallback= JS(
              'function(settings) {
                         Shiny.bindAll(this.api().table().node());}'),
            initComplete = htmlwidgets::JS(
              "function(settings, json) {",
              "$(this.api().table().header()).css({'background-color': '#002D72', 'color': 'white', 'font-family': 'Helvetica'});",
              "}"
            )
          )
        )
      })

Is there anything in particular that may be causing this behaviour?

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • colincolin Posts: 15,177Questions: 1Answers: 2,590

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

Sign In or Register to comment.