闪亮-选中数据表中的复选框时为true或false值 [英] Shiny - true or false value when check a checkbox in datatable
本文介绍了闪亮-选中数据表中的复选框时为true或false值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对R闪亮代码有疑问,当我想在复选框中看到true或false值时,我该怎么办?因为当我尝试print(input $ row1)时结果为NULL,并且当我在复选框中进行检查时,print语句中没有响应。这是代码:
i have problem with R shiny code, what i must do, when i want to see the true or false value in checkbox? because when i try print(input$row1) the result is NULL, and when i give check in the checkbox there are no respon in print statement. this is the code :
library(shiny)
library(DT)
mymtcars = mtcars
mymtcars$id = 1:nrow(mtcars)
runApp(
list(ui = pageWithSidebar(
headerPanel('Examples of DataTables'),
sidebarPanel(
),
mainPanel(
uiOutput("mytable")
)
)
, server = function(input, output, session) {
output$mytable = renderUI({
addCheckboxButtons <- paste0('<input type="checkbox" id="row', mymtcars$id, '">',"")
yyy<- cbind(mymtcars[, names(mymtcars[,2:4]), drop=FALSE],Pick=addCheckboxButtons)
#try
print(input$row1) #didnt work
print(input$row2) #didnt work
#Display table with checkbox buttons
list(
renderDataTable(yyy,
options = list(orderClasses = TRUE,
lengthMenu = c(5, 25, 50),
pageLength = 25,
callback = JS("function(table) {
table.on('change.dt', 'tr td input:checkbox', function() {
setTimeout(function () {
Shiny.onInputChange('rows', $(this).add('tr td input:checkbox:checked').parent().siblings(':last-child').map(function() {
return $(this).text();
}).get())
}, 10);
});
}")),escape = FALSE
))
}
)
}
)
)
推荐答案
查看简短示例(仅适用于row1)
See short example ( only for row1)
1)您可以使用 Shiny.bindAll
2)您需要请参见观察
library(shiny)
library(DT)
mymtcars = mtcars
mymtcars$id = 1:nrow(mtcars)
runApp(
list(ui = pageWithSidebar(
headerPanel('Examples of DataTables'),
sidebarPanel(
checkboxGroupInput('show_vars', 'Columns to show:', names(mymtcars),
selected = names(mymtcars))
,textInput("collection_txt",label="Foo")
),
mainPanel(
DT::dataTableOutput("mytable")
)
)
, server = function(input, output, session) {
observe({
print(input$row1)
})
output$mytable = DT::renderDataTable({
#Display table with checkbox buttons
DT::datatable(cbind(Pick=paste0('<input type="checkbox" id="row', mymtcars$id, '" value="', mymtcars$id, '">',""), mymtcars[, input$show_vars, drop=FALSE]),
options = list(orderClasses = TRUE,
lengthMenu = c(5, 25, 50),
pageLength = 25 ,
drawCallback= JS(
'function(settings) {
Shiny.bindAll(this.api().table().node());}')
),selection='none',escape=F)
} )
})
)
这篇关于闪亮-选中数据表中的复选框时为true或false值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文