【发布时间】:2021-05-16 15:15:24
【问题描述】:
当单选按钮输入值嵌入到闪亮的 DataTable 中时,我无法访问它们。我的代码基于此示例:Radio Buttons in DT
它访问第一次传递的值并将它们显示在下面,如以下屏幕截图所示:
First pass screenshot
一旦我更改了响应式重新渲染表格的输入,单选按钮中的值将不再显示,而是停留在第一次传递值上。这可以在以下屏幕截图中看到。 Second pass screenshot
第一次通过后,输入不再更新以反映单选按钮的选择。原始输入似乎冻结了,我找不到访问当前按钮值的方法。
提前感谢您的帮助!
这是上面例子的代码:
library(shiny)
library(DT)
library(data.table)
shinyApp(
ui = fluidPage(
title = 'Radio buttons in a table',
selectInput('questions','Pick',c(1,2)),
DT::dataTableOutput('foo'),
verbatimTextOutput('sel')
),
server = function(input, output, session) {
myData = reactiveValues(m = NULL)
temp = month.abb
observeEvent(input$questions,{
m = data.table(
month1 = temp[1:5],
A = '1',
B = '2',
C = '3',
QWE = runif(5)
)
m[, A := sprintf(
'<input type="radio" name="%s" value="%s"/>',
month1, m[, A]
)]
m[, B := sprintf(
'<input type="radio" name="%s" value="%s"/>',
month1, m[, B]
)]
m[, C := sprintf(
'<input type="radio" name="%s" value="%s"/>',
month1, m[, C]
)]
myData$m = m
})
output$foo = DT::renderDataTable({
m = myData$m
print(m)
}
, escape = FALSE, selection = 'none', server = FALSE, rownames=FALSE,
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]]))
})
}
)
【问题讨论】:
标签: javascript r shiny radio-button dt