首页 > 解决方案 > R Shiny - 无法检索在 DT 表中创建的输入控件的值

问题描述

我按照 DT 官方页面中的这个示例在 DT 表中创建输入控件。我创建了类似的东西,但我还需要一个可编辑的表格。因此,我需要设置(server = TRUE在需要的renderDTRTFM 之后实现)。所以现在我尝试按照这个在 DT 表中呈现复选框输入的示例,但使用. 问题是现在我无法在服务器端获取输入控件的值,这在. 谁能告诉我如何在此设置中检索服务器端的控制值。reloadDataserver = TRUEserver = TRUEserver = FALSE

library(shiny)
library(DT)
shinyApp(
  ui = fluidPage(
    title = 'Radio buttons in a table',
    DT::dataTableOutput('foo'),
    verbatimTextOutput('sel')
  ),
  server = function(input, output, session) {
    m = matrix(
      as.character(1:5), nrow = 12, ncol = 5, byrow = TRUE,
      dimnames = list(month.abb, LETTERS[1:5])
    )
    for (i in seq_len(nrow(m))) {
      m[i, ] = sprintf(
        '<input type="radio" name="%s" value="%s"/>',
        month.abb[i], m[i, ]
      )
    }
    m
    output$foo = DT::renderDataTable(
      m, escape = FALSE, selection = 'none', server = TRUE,
      options = list(dom = 't', paging = FALSE, ordering = FALSE),
      callback = JS("table.rows().every(function(i, tab, row) {
          var $this = $(this.node());
          $this.attr('id', this.data()[0]);
          $this.addClass('shiny-input-radiogroup');
        });
        Shiny.unbindAll(table.table().node());
        Shiny.bindAll(table.table().node());")
    )
    output$sel = renderPrint({
      str(sapply(month.abb, function(i) input[[i]]))
    })
  }
)

标签: rshinydt

解决方案


推荐阅读