gpt4 book ai didi

重置Shiny R中DT::renderDataTable()的行选择

转载 作者:行者123 更新时间:2023-12-04 06:17:21 25 4
gpt4 key购买 nike

我转载了由Yihui Xie(https://yihui.shinyapps.io/DT-rows/)编写的示例 Shiny 应用程序。该应用程序使用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")
}
})

})

用户界面
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
)))

最佳答案

DT (> = 0.1.16)的current development version中,可以使用selectRows()方法清除选择。请参阅documentation中的“操作现有DataTables实例”部分。

关于重置Shiny R中DT::renderDataTable()的行选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31068319/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com