[英]disable does not work for downloadButton when using uiOutput/renderUI
I have a simple ui/server modules.我有一个简单的 ui/server 模块。 When I try using uiOutput/renderUI, the disable/enable function does not work.
当我尝试使用 uiOutput/renderUI 时,禁用/启用 function 不起作用。 But, if I call ui module directly in the ui, it works fine.
但是,如果我直接在 ui 中调用 ui 模块,它就可以正常工作。
library(shiny)
library(shinyjs)
library(shinydashboard)
my_UI <- function(id = "xyz") {
ns <- NS(id)
tagList(
downloadButton(ns("dl"), "Download")
)
}
my_Server <- function(id = "xyz") {
moduleServer(id,
function(input, output, session) {
disable("dl")
}
)
}
ui <- dashboardPage(
dashboardHeader(title = "test"),
dashboardSidebar(disable = TRUE),
dashboardBody(
useShinyjs(),
uiOutput("app_ui")
# my_UI()
)
)
server <- function(input, output, session) {
output$app_ui <- renderUI({
my_UI()
})
my_Server()
}
shinyApp(ui, server)
That's because the download button is not rendered yet when disable
is executed.那是因为执行
disable
时下载按钮还没有渲染。 You can use shinyjs::delay
to delay the execution.您可以使用
shinyjs::delay
来延迟执行。 Actually this works with a delay of 0ms, because this function also puts the expression it executes in a queue.实际上这会延迟 0 毫秒,因为这个 function 还将它执行的表达式放入队列中。
my_Server <- function(id = "xyz") {
moduleServer(
id,
function(input, output, session) {
delay(0, disable("dl"))
}
)
}
We can also start with the button already disabled using shinyjs::disabled()
我们也可以使用
shinyjs::disabled()
从已经禁用的按钮开始
my_UI <- function(id = "xyz") {
ns <- NS(id)
tagList(
shinyjs::disabled(downloadButton(ns("dl"), "Download"))
)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.