R Shiny DT Row Select 和行编辑冲突
R Shiny DT Row Select and Row Edit Collision
我有一个正在开发的 Shiny 应用程序,我正在使用 renderDataTable
向用户显示数据框。现在,用户需要单击 table 的一行以提取有关该行的其他信息。同时,我将数据 table 设置为 'row' editable。这确实导致了一些问题。要启动该行的编辑模式,需要双击该行,但多次单击会切换该行的选定状态。
有没有一种方法无需双击即可启动行编辑或双击时禁用行选择状态?
编辑:这是我对 DT 的调用:
output$image_list = DT::renderDataTable({
if(!('data.frame' %in% class(values$images))) {
return(NULL)
}
datatable(values$images,
rowname=FALSE,
options=list(columnDefs = list(list(visible=FALSE, targets=c(0, 1, 3, 6)))),
colnames=c('ID', 'Full File Name', 'Filename', 'Directory', 'Range Scale', 'Heading', 'Status'),
selection = 'single',
editable = list(target='row', disable = list(columns=c(0, 1, 2, 3, 6)))
) %>%
formatStyle('Status', target='row', backgroundColor = styleEqual(c('Incomplete', 'Complete'), c('#FF9999', '#99FF99')))
})
版本信息
Tool | Version
-----|--------
R | 4.0
Shiny| 1.5.0
DT | 0.15
我不确定是否理解,但也许这会有所帮助。使用下面的应用程序,您只需单击 non-editable 列中的单元格即可 select 一行。因此,double-clicking 可编辑单元格不会触发行 selection。不确定这是否有帮助...告诉我什么。
library(shiny)
library(DT)
dat <- iris[1:6,]
nonEditableColumns <- c(3, 4)
ui <- fluidPage(
br(),
DTOutput("dtable")
)
server <- function(input, output, session) {
output[["dtable"]] <- renderDT({
datatable(
dat,
extensions = "Select",
selection = "none",
editable = list(
target = "row",
disable = list(columns = nonEditableColumns)
),
options = list(
columnDefs = list(
list(className = "selectable", targets = nonEditableColumns),
list(className = "dt-center", targets = "_all")
),
select = list(style = "single",
selector = "td.selectable")
)
)
}, server = FALSE)
}
shinyApp(ui, server)
我有一个正在开发的 Shiny 应用程序,我正在使用 renderDataTable
向用户显示数据框。现在,用户需要单击 table 的一行以提取有关该行的其他信息。同时,我将数据 table 设置为 'row' editable。这确实导致了一些问题。要启动该行的编辑模式,需要双击该行,但多次单击会切换该行的选定状态。
有没有一种方法无需双击即可启动行编辑或双击时禁用行选择状态?
编辑:这是我对 DT 的调用:
output$image_list = DT::renderDataTable({
if(!('data.frame' %in% class(values$images))) {
return(NULL)
}
datatable(values$images,
rowname=FALSE,
options=list(columnDefs = list(list(visible=FALSE, targets=c(0, 1, 3, 6)))),
colnames=c('ID', 'Full File Name', 'Filename', 'Directory', 'Range Scale', 'Heading', 'Status'),
selection = 'single',
editable = list(target='row', disable = list(columns=c(0, 1, 2, 3, 6)))
) %>%
formatStyle('Status', target='row', backgroundColor = styleEqual(c('Incomplete', 'Complete'), c('#FF9999', '#99FF99')))
})
版本信息
Tool | Version
-----|--------
R | 4.0
Shiny| 1.5.0
DT | 0.15
我不确定是否理解,但也许这会有所帮助。使用下面的应用程序,您只需单击 non-editable 列中的单元格即可 select 一行。因此,double-clicking 可编辑单元格不会触发行 selection。不确定这是否有帮助...告诉我什么。
library(shiny)
library(DT)
dat <- iris[1:6,]
nonEditableColumns <- c(3, 4)
ui <- fluidPage(
br(),
DTOutput("dtable")
)
server <- function(input, output, session) {
output[["dtable"]] <- renderDT({
datatable(
dat,
extensions = "Select",
selection = "none",
editable = list(
target = "row",
disable = list(columns = nonEditableColumns)
),
options = list(
columnDefs = list(
list(className = "selectable", targets = nonEditableColumns),
list(className = "dt-center", targets = "_all")
),
select = list(style = "single",
selector = "td.selectable")
)
)
}, server = FALSE)
}
shinyApp(ui, server)