[英]How to pre-select cells in Shiny DT datatables
有沒有辦法預先選擇 shiny DT 數據表中的單元格而不是行?
library(shiny)
if (packageVersion('DT') < '0.1.3') devtools::install_github('rstudio/DT')
library(DT)
shinyApp(
ui = fluidPage(
fluidRow(
h1('Client-side processing'),
DT::dataTableOutput('x1')
)
),
server = function(input, output, session) {
output$x1 = DT::renderDataTable(
iris, server = FALSE,
selection = list(mode = 'multiple', selected = c(1, 3, 8, 12),target="cell")
)
}
)
請參閱 github 指南,其中包含您正在尋找的內容(在這個問題和您最近發布的其他問題中)。 https://rstudio.github.io/DT/shiny.html
2.1.4 預選
datatable() 的選擇參數還可以包括一個組件,該組件被選中以指定在初始化表時要預先選擇哪些行/列/單元格。 當 target = 'row' 或 'column' 時,selected 是行或列索引的向量。 對於target = 'row+column' 的情況,選擇的應該是兩個組件rows 和cols 的列表,例如list(rows = c(1, 2, 4, 9), cols = c(1, 3))。 對於 target = 'cell',它應該是一個包含兩列的矩陣:第一列是選定單元格的行索引,第二列是列索引。
為了讓它 select 某個單元格,你必須給它坐標(行和列)。
library(DT)
shinyApp(
ui = fluidPage(
fluidRow(
h1('Client-side processing'),
DT::dataTableOutput('x1')
)
),
server = function(input, output, session) {
output$x1 = DT::renderDataTable(
iris, server = FALSE,
selection = list(mode = 'multiple', selected = matrix(c(1, 3, 2, 4), nrow = 2, ncol = 3),target="cell")
)
}
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.