如何解决使 conditionalPanel 与 R 闪亮 Golem 包中的输入参数一起工作
我通常看到 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,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)
)
}
解决方法
get_golem_options("input")
的美妙之处在于它也可以在您的用户界面中使用 :)
所以我认为你可以做一些更简单的事情,比如:
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(...)
}
)
)
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。