【问题标题】:Shiny DT: selectColumns not working?闪亮的 DT:selectColumns 不起作用?
【发布时间】:2018-08-14 05:18:34
【问题描述】:

我有以下示例应用程序(下面的代码)。这个想法是,如果用户选择第二列(索引为 1),则选择转到第三列(索引为 2),因为我不希望用户能够选择第二列(如据我所知,没有内置方法可以阻止用户选择 DT 中的特定列)。

问题在于selectRows(tableProxy, c(2) 有效(行选择的一个简单示例),selectColumns(tableProxy, c(2)) 仅取消选择当前选择的列,而不选择第三列。

我的语法有问题,还是这是一个错误?如果是错误,是否有解决方法?

可重现的例子:

library(shiny)

# Define UI for application that draws a histogram
ui <- fluidPage(

  fluidRow(
    tags$div(title = "Iris table",
             DT::dataTableOutput("irisTable"))
  )
)

# Define server logic required to draw a table
server <- function(input, output) {

  output$irisTable <- DT::renderDT(datatable(head(iris, 20), options = list(paging = FALSE, searching = FALSE),
  rownames = FALSE, 
  selection = list(target = 'row+column', mode='single', selected = list(rows = c(NULL), cols = c(2)))
  ) %>% 
    formatStyle(0, target= 'row',color = 'black', 
                lineHeight='70%', padding = '3px 3px', fontSize = '80%')
  )

  tableProxy <- dataTableProxy("irisTable")

  observeEvent(input$irisTable_columns_selected, {
    if (input$irisTable_columns_selected == 1) {
      #tableProxy %>% selectColumns(2)
      selectRows(tableProxy, c(2))
      selectColumns(tableProxy, c(2))
    }
  })
}

# Run the application 
shinyApp(ui = ui, server = server)

更新:我已经使用发布的示例代码here(转换为使用单个文件 Shiny 应用程序)尝试了上述方法,我也遇到了同样的问题。我已经重新安装了 DT 包,它并没有解决问题。

【问题讨论】:

    标签: r shiny dt


    【解决方案1】:

    这是 DT 的一个错误,应该通过 PR rstudio/DT#528 修复。您可以通过调用devtools::install_github("rstudio/DT") 安装开发版进行测试。

    【讨论】:

    • 谢谢,我已经放弃了这个。期待让它发挥作用。
    猜你喜欢
    • 2017-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-02
    • 2019-11-18
    • 2017-08-25
    • 1970-01-01
    • 2018-09-25
    相关资源
    最近更新 更多