R:datatable中的多个updateSelectInput应在按下按钮时执行,但仅更新第一个按钮
我有一个简单的表格,其中一列中的每个单元格都有下拉列表(selectInput)。每当单击按钮“Go”时,这些下拉列表中的每一个都应更新。不幸的是,只有第一个更新了。据我所知,问题在于第一个“updateSelectInput”会立即触发输出表的呈现。我必须在代码中更改什么才能使其工作?非常感谢您的任何建议R:datatable中的多个updateSelectInput应在按下按钮时执行,但仅更新第一个按钮,r,shiny,R,Shiny,我有一个简单的表格,其中一列中的每个单元格都有下拉列表(selectInput)。每当单击按钮“Go”时,这些下拉列表中的每一个都应更新。不幸的是,只有第一个更新了。据我所知,问题在于第一个“updateSelectInput”会立即触发输出表的呈现。我必须在代码中更改什么才能使其工作?非常感谢您的任何建议 library(shiny) library(DT) ui <- fluidPage( title = 'Updateable Selectinput column in a t
library(shiny)
library(DT)
ui <- fluidPage(
title = 'Updateable Selectinput column in a table',
h3("Source:", tags$a("Yihui Xie", href = "https://yihui.shinyapps.io/DT-radio/")),
shiny::actionButton(inputId = "btn", label = "Go"),
DT::dataTableOutput('foo'),
verbatimTextOutput('sel')
)
server <- function(input, output, session) {
data <- head(iris, 5)
for (i in 1:nrow(data)) {
data$species_selector[i] <- as.character(selectInput(paste0("sel", i), "", choices = unique(iris$Species), width = "100px"))
}
observeEvent(input[["btn"]], {
for (i in 1:nrow(data)){
updateSelectInput(session = session, inputId = paste0("sel", i), label = "", choices = 1:nrow(data))
}
})
output$foo = DT::renderDataTable(data,
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-container');
});
Shiny.unbindAll(table.table().node());
Shiny.bindAll(table.table().node());")
)
output$sel = renderPrint({
input[["btn"]]
str(sapply(1:nrow(data), function(i) input[[paste0("sel", i)]]))
})
}
shinyApp(ui, server)
库(闪亮)
图书馆(DT)
ui我不明白发生了什么,但它与label=NULL一起工作:
updateSelectInput(session = session, inputId = paste0("sel", i), label = NULL, choices = 1:nrow(data))
嗨,斯泰芬,非常感谢!!很奇怪,这工作。。。最近几天,这个问题让我发疯。所以,让我们祈祷它仍然可以在更大的模块环境中工作;)。再次感谢!:)