在https://yihui.shinyapps.io/DT-edit/上的例子中,当editable = "column"
时,结果将不会呈现并保留在表中。实际上,它们仅在editable = TRUE
或editable = "cell"
时有效。
从上面的链接中挑选出以下代码,我添加了一个Click
按钮来查看input
元素中的内容。
在使用editable = "column"
(允许输入到列单元格)选择单元格后使用Click
时,input$x1_columns_selected
中未显示任何变化。
有没有人能具体说明为什么以及如果这曾经正确工作?我看不出像这样的功能将如何被打破,它似乎非常有用。
library(shiny)
library(DT)
dt_output = function(title, id) {
fluidRow(column(
12, h1(paste0('Table ', sub('.*?([0-9]+)$', '\\1', id), ': ', title)),
hr(),
actionButton("click_action", "Click"),
hr(),
DTOutput(id)
))
}
render_dt = function(data, editable = 'cell', server = TRUE, ...) {
renderDT(data, selection = 'none', server = server, editable = editable, ...)
}
shinyApp(
ui = fluidPage(
title = 'Double-click to edit table cells',
dt_output('client-side processing (editable = "column")', 'x1'),
),
server = function(input, output, session) {
d1 = iris[1:5,]
d1$Date = Sys.time() + seq_len(nrow(d1))
# client-side processing
output$x1 = render_dt(d1, 'column', FALSE)
observe(str(input$x1_cell_edit))
observeEvent(input$click_action, {
print(input)
print(input$x1_cells_selected)
print(input$x1_columns_selected)
print(input$x1_rows_all)
print(input$x1_rows_current)
print(input$x1_rows_selected)
print(input$x1_search)
#print(input$x1_state)
})
}
)
1条答案
按热度按时间ih99xse11#
编辑列
事实证明,这确实有效;只不过在单元格外单击并不足以注册编辑,但按Ctrl + Enter键有效。(我从this page of examples上表2的鼠标悬停文本中学到了这一点。)因此,例如,假设您编辑
Sepal.Width
并将第一个值设置为7:按下Ctrl + Enter后,您的应用将显示以下输出:
这意味着第2列的第1-5行被编辑,它们的值被设置为7(更改的值)、3(与之前相同)、3.2等。
选定列
存储在
input$x1_columns_selected
中的值与编辑列无关。相反,如果表设置了selection = list(target = 'column')
选项,则当用户单击它时可以选择整个列。Click
按钮将打印所选列的索引。下面是设置了该选项的应用程序示例(并且Click
按钮的输出仅限于所选列):如果单击
Sepal.Width
列中的任意位置,将看到以下内容:然后,如果您单击该按钮,就会得到以下输出:
这意味着选择了列2。