Skip to content

Instantly share code, notes, and snippets.

@juba
Last active July 1, 2019 12:12
Show Gist options
  • Save juba/fcc44d15f76c8bdf0c1640bbcd610648 to your computer and use it in GitHub Desktop.
Save juba/fcc44d15f76c8bdf0c1640bbcd610648 to your computer and use it in GitHub Desktop.
## Generate unique id for this table
tab_id <- paste0("mytab_", session$token)
output$table <- DT::renderDT({
## Enable stateSave and configure callbacks to save and restore state
## to/from sessionStorage
options <- list(
stateSave = TRUE,
stateSaveCallback = DT::JS(paste0("function(settings, data) {
sessionStorage.setItem('", tab_id, "', JSON.stringify(data));
}")),
stateLoadCallback = DT::JS(paste0("function(settings, callback) {
return JSON.parse(sessionStorage.getItem('", tab_id, "'));
}"))
)
## Generate dataTable with options
DT::datatable(df(), options = options)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment