I am trying to get the left scroll position of my DT table in shiny.
Here is an example application for how I was attempting to capture it.
library(shiny)
library(DT)
js_save_scroll <- '$(document).on("shiny:connected", function(settings, json) {
console.log("Test log");
$("#tbl").on("click", function() {
console.log("Table clicked");
var table = $("#tbl");
var scrollPos = $("#tbl").scrollLeft();
console.log("Scroll position: " + scrollPos);
});
});
'
df <- data.frame(matrix(rnorm(1000), nrow = 100, ncol = 50))
shinyApp(
ui = fluidPage(
tags$script(js_save_scroll),
DTOutput('tbl')
),
server = function(input, output) {
output$tbl = renderDT(df)
}
)
When I check the console in my browser, scrollPos is always set to zero.
New contributor
hblum is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.