javascript - 带有服务器端处理的 Shiny App 中的 JS 回调
问题描述
我对 Shiny 应用程序中的 JavaScript 回调很陌生。
有人可以向我解释为什么如果我将服务器切换到 TRUE 则以下代码片段将不起作用?
“sel”输出不再正确呈现单选按钮的值。换句话说,即使我单击按钮,renderPrint 仍然显示 NULL 12 个月。
我在这里找到了这个例子:https
://yihui.shinyapps.io/DT-radio/
提前谢谢你
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 = 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]]))
})
}
)