【发布时间】:2019-03-16 22:19:42
【问题描述】:
我正在创建一个闪亮的应用程序,它将从数据库表中获取值并根据用户请求更新另一个表。单击添加按钮后,就会出现问题。复选框的值与之前的值相同,并且不会从数据库中获取新值。
ui <- fluidPage(
checkboxGroupInput("inCheckboxGroup", "Available names", td),
checkboxGroupInput("inCheckboxGroup2", "Present names",c(ch1,ch)),
actionButton("action", label = "Add")
)
td、ch1 和 ch 是从数据库中收集的列表。
z <- NULL
server <- function(input, output, session) {
# checkbox listener
observe({
x <- input$inCheckboxGroup
y <- NULL
if (is.null(x))
x <- character(0)
# Get the names for these ids
for (i in x){
y <- dbFetch(dbSendQuery(conn, paste0("--sql query--") ))
z <- c(z,y[,1])
}
# Print the names from previous block into the checkboxes
updateCheckboxGroupInput(session, "inCheckboxGroup2",
choices = c(ch1,z),
selected = z)
})
# button listener
observeEvent(input$action,{
for(i in input$inCheckboxGroup){
rs <- dbSendQuery(conn, paste0("--sql query--"))
dbFetch(rs)
}
showNotification("Row inserted")
})
}
我尝试创建一个页面刷新功能或输入重置来解决问题。但即使重新加载页面也无济于事。最好的方法是什么?
【问题讨论】:
-
为什么
observeEvent中没有updateCheckboxGroupInput用于单击操作按钮?
标签: r shiny shiny-server shinyjs