我通常会看到 conditionalPanel 在发生事件时工作,例如按下按钮或选中复选框等。但是在这里,我希望它与运行应用程序时传递的参数一起工作。我试图仅在“输入”参数不为空时显示条件面板,但面板一直出现。这是我尝试过的代码:
app_ui.R
#' The application User-Interface
#'
#' @param request Internal parameter for `{shiny}`.
#' DO NOT REMOVE.
#' @import shiny
#' @noRd
app_ui <- function(request) {
tagList(
# Leave this function for adding external resources
golem_add_external_resources(),
# List the first level UI elements here
fluidPage(
h1("testapp"),
conditionalPanel(
condition = "!is.null(r.input)",
p('there is an input ')
)
)
)
}
app_server.R
#' The application server-side
#'
#' @param input,output,session Internal parameters for {shiny}.
#' DO NOT REMOVE.
#' @import shiny
#' @noRd
app_server <- function( input, output, session ) {
# List the first level callModules here
r <- reactiveValues(query = reactiveValues())
observe({
input <- golem::get_golem_options("input")
r$input <- input
})
}
run_app.R
#' Run the Shiny Application
#'
#' @param input input
#'
#' @export
#' @importFrom shiny shinyApp
#' @importFrom golem with_golem_options
run_app <- function(
input = NULL
) {
with_golem_options(
app = shinyApp(
ui = app_ui,
server = app_server
),
golem_opts = list(input = input)
)
}