我通常会看到conditionalPanel在事件发生时工作,比如按下按钮或选中复选框等,但在这里,我希望它能够在运行应用程序时传递一个参数。只有当“输入”参数不是null时,我才会试图显示条件面板,但是面板总是会出现。下面是我尝试过的代码:
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)
)
}发布于 2021-07-22 06:23:47
get_golem_options("input")的优点在于它也可以在您的UI中使用:)
所以我认为你可以做一些更简单的事情,比如:
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"),
if (!is.null(golem::get_golem_options("input")){
your_UI_here(...)
}
)
)
}https://stackoverflow.com/questions/68479257
复制相似问题