[英]shiny dt bookmarking state
親愛的R Shiny社區,
我正在嘗試為Shiny應用程序創建一個書簽狀態,在其中使用DT包渲染表格。 例如,在下面粘貼的應用程序中,我想在搜索字段中鍵入一些文本,該文本對數據進行分組並添加書簽,例如獲得我可以共享的URL。 另一個用戶可以使用URL並查看表的相同子集,而無需在搜索字段中再次鍵入文本。 使用以下代碼,我希望看到帶有選項1代碼的“書簽”按鈕或帶有選項2的動態URL,但是不幸的是,它無法按預期工作。 有誰知道用DT渲染表格時如何設置書簽狀態?
這是可復制的代碼:
選項1
library(shiny)
ui <- function(request) {
fluidPage(DT::dataTableOutput('tbl'))
}
server = function(input, output) {
output$tbl = DT::renderDataTable(
iris, options = list(lengthChange = FALSE)
)
}
shinyApp(ui, server, enableBookmarking = "url")
選項2
library(shiny)
ui <- function(request) {
fluidPage(DT::dataTableOutput('tbl'))
}
server = function(input, output) {
observe({
output$tbl = DT::renderDataTable(
iris, options = list(lengthChange = FALSE)
)
})
onBookmarked(function(url) {
updateQueryString(url)
})
}
shinyApp(ui, server, enableBookmarking = "url")
非常感謝您的時間和幫助!
根據以下討論, https://groups.google.com/forum/#!topic / shiny-discuss / DvWhqwZ8OKw我找到了答案。
我能夠修改選項1,這是最小的可重現應用程序。 只需在全局搜索字段中鍵入一個字符串,單擊底部的書簽按鈕,復制URL並共享即可。
library(DT)
library(shiny)
ui <- function(request) {
fluidPage(
DT::dataTableOutput('tbl')
, bookmarkButton(label = "Bookmark", title = "Link to this view")
)
}
server = function(input, output) {
# exclude some values query variables from url
setBookmarkExclude(names = c("resTable_rows_all",
"resTable_cell_clicked"))
# proxy for table manipulations
tbl_proxy <- dataTableProxy("tbl")
# restore table selection and search
onRestored(function(state) {
# req(state$input$resTable_search)
DT::updateSearch(tbl_proxy,
keywords = list(global = state$input$tbl_search))
})
output$tbl <- renderDataTable(iris)
}
shinyApp(ui, server, enableBookmarking = "url")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.