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

Preserving scroll client side #1161

Open
andrewjmc opened this issue Dec 17, 2024 · 0 comments
Open

Preserving scroll client side #1161

andrewjmc opened this issue Dec 17, 2024 · 0 comments

Comments

@andrewjmc
Copy link

I am having trouble preserving scroll position in unpaged client-side DT in Shiny. In my real application, the data is a reactiveVal created in the global context and shared across users of a multi-user application. Updates can come from a user's own edits or other users.

When coding my app, I was unaware of the dataTableProxy approach.

A minimal example is below. With my approach updating the reactive global data frame, the scroll position is not preserved (clearly I am forcing a refresh of the entire table). The dataTableProxy approach also doesn't work with the client side table, and I get an "invalid JSON response" error.

If, for whatever reason, the out-of-the-box functionality doesn't work for my case, I'd be keen to understand the client-side events I might utilise to cache the current scroll position, and to catch a table redraw and scroll to the stored position.

Grateful for any advice.

library(DT)
library(shiny)
library(magrittr)

ui <- fillPage(
  DTOutput("table", fill=TRUE, height="100%")
)

data <- data.frame(A=paste("Hello", LETTERS), B=paste("Hello", LETTERS), C=paste("Hello", LETTERS))
data %<>% reactiveVal()

server <- function(input, output){
  
  output$table = renderDT(
    data(), server=FALSE, editable=TRUE, options=list(paging=FALSE), height="100%", fillContainer=TRUE
  )

  #proxy <- dataTableProxy("table")
  
  observeEvent(input$table_cell_clicked, ignoreInit=TRUE, ignoreNULL=TRUE, {
    print("clicked")
    local_data <- isolate(data())
    local_data[1,1] <- paste(local_data[1,1], "Hello")
    data(local_data)
    #alternative approach
    #proxy <- replaceData(proxy, local_data)
  })
}

shinyApp(ui, server)
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

1 participant