我再现了由Yihui Xie编写的一个闪亮的应用程序示例(https://yihui.shinyapps.io/DT-rows/).该应用程序使用DT::renderDataTable()允许行选择.
一切都很好.然而,我想知道是否可以重置行选择(即撤消点击选择)?我已经尝试使用操作按钮重置s = input$x3_rows_selected(请参阅下面的脚本).
使用我当前的脚本,s = input$x3_rows_selected确实会被清空,但我可以不重新填充它.此外,所选行仍然被点击(阴影)
有没有人有想法?DT :: renderDataTable()中是否有一个选项来重置选择?或者有没有人有解决方法的想法?
谢谢!
我的修改(操作按钮)示例表单https://yihui.shinyapps.io/DT-rows/):
library(shiny)
library(DT)
shinyServer(function(input, output, session) {
# you must include row names for server-side tables
# to be able to get the row
# indices of the selected rows
mtcars2 = mtcars[, 1:8]
output$x3 = DT::renderDataTable(mtcars2, rownames = TRUE, server = TRUE)
# print the selected indices
selection <- reactive({
if (input$resetSelection)
vector() else input$x3_rows_selected
})
output$x4 = renderPrint({
if (length(selection())) {
cat("These rows were selected:\n\n")
output <- selection()
cat(output, sep = "\n")
}
})
})
Run Code Online (Sandbox Code Playgroud)
library(shiny)
shinyUI(
fluidPage(
title = 'Select Table Rows',
h1('A Server-side Table'),
fluidRow(
column(9, DT::dataTableOutput('x3')),
column(3, verbatimTextOutput('x4'),
actionButton('resetSelection',
label = "Click to reset row selection"
) # end of action button
) #end of column
)))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6130 次 |
| 最近记录: |