I have reactable table that is very wide. Most of the time I am interested in the right-most columns and so would want to show them by default. This is typical for time series tables, where the most recent data is in focus (but you might still want to check the long-term history) and is usually shown on the right. How can I ensure the scrollbar is on the right by default - as simple as possible?
library(reactable)
df <- setNames(data.frame(as.list(1:30)), 1:30)
reactable(df)
This might help:
library(reactable)
library(htmlwidgets)
df <- setNames(data.frame(as.list(1:30)), 1:30)
# Custom JS to scroll the table to the right
scroll_right_js <- "function(el, x) {
var container = el.querySelector('.rt-table');
container.scrollLeft = container.scrollWidth;
}"
# htmlwidgets::onRender() will execute the JS after the table is rendered
htmlwidgets::onRender(
x = reactable(df),
jsCode = scroll_right_js
)