我试图观察一个闪亮的事件。如果我手动定义了一个无线电,它将被正确观察-输出:print(paste0("SELECT * FROM daten;"))
。我想避免在ui.r中编写十分之几的单选按钮。因此,我在服务器部分编写了一个循环。
但是,相同的watchEvent()不会对我的“循环列出”单选按钮做出反应,这些单选按钮正确地内置在闪亮的应用程序中。我不知道为什么。
我写了一个最小的例子:
library(shiny)
shinyApp(
ui = fluidPage(
####### manually set radio #######
print("This radio 'pd1' will be observed:"),
radioButtons(inputId = "pd1", label = "value:", choices = c("?", "0", "1")),
br(), br(),
####### versus looped set set radio #######
uiOutput("scrlst"),
),
server = function(input, output) {
tablscr <- data.frame("1","question")
###################### observeEvent
##### "counter" for several items (in this case just 1 item)
rv <- reactiveValues(counter = 0)
lapply(1:dim(tablscr)[1], function(i) {
isolate({qnum <- paste0('pd', rv$counter <- rv$counter + 1)})
observeEvent(input[[qnum]], {print(paste0("SELECT * FROM daten;"))})
})
### output for tenths of items in one loop (in this case just 1 item)
output$scrlst <- renderUI({
tagList(
scr <- list(),
for (sq in 1:dim(tablscr)[1]){
scr[[sq]] = list(sq,
print("This radio 'pd1' will not be observed:"),
radioButtons(inputId = "pd1", label = "value:", choices = c("?", "0", "1")),
br(),
br()
)
},
return(scr),
)
})
}
)
答案 0 :(得分:0)
您的BatchBlock
包含循环和return语句听起来很奇怪。此外,您有一个重复的ID tagList
。这是一个工作代码:
pd1