Hi:
I want to create a bookmark from this table when some cells are selected. The 'Bookmark...' button gives a direction in which the selected cells have disappeared. That is, the bookmark gives the same direction for all selections, and corresponds to the empty table. Can you help me? Thanks.
(https://yosu-yurramendi.shinyapps.io/QuestionBookmark/)
library(shiny)
library(DT)
enableBookmarking(store = "url")
ui <- function(request){fluidPage(
HTML("
(select some cells)
"),DT::dataTableOutput(outputId = "pattern", width = "25%", height = "auto"),
br(),
bookmarkButton(id = "bookmark")
)}
server <- function(input, output, session) {
nrow <- 3
ncol <- 4
proxy <- dataTableProxy('pattern')
checkboxes <- reactive({
as.data.frame(matrix(rep(NA, nrowncol), nrow = nrow, ncol = ncol,
dimnames = list(paste("m", 1:nrow, sep = ""),
paste("n", 1:ncol, sep = ""))))
})
tableData <- reactiveValues(checkboxes = NULL)
observe({tableData$checkboxes <<- checkboxes()})
#Update the table when clicked
observeEvent(req(input$pattern_cells_selected),
{tableData$checkboxes[input$pattern_cells_selected] <-
ifelse(is.na(tableData$checkboxes[input$pattern_cells_selected]), "", NA)
replaceData(proxy = proxy, data = tableData$checkboxes)
}) # observeEvent
output$pattern <- DT::renderDataTable({ checkboxes() },
selection = list(mode = "single", target = 'cell'),
options = list(
columnDefs = list(list(className = 'dt-center', targets = "_all")),
dom = "t", ordering = FALSE),
escape = FALSE
) # renderDataTable
observeEvent(input$bookmark, {session$doBookmark()})
} # server
shinyApp(ui, server)