使 conditionalPanel 在 R shiny Golem 包中使用输入参数
making conditionalPanel work with input parameter in a R shiny Golem package
我通常会看到条件面板与事件发生一起工作,例如按下按钮或选中复选框等。但在这里,我希望它与我 运行 应用程序时传递的参数一起工作。我试图仅在“输入”参数不为空时显示条件面板,但面板一直出现。这是我试过的代码:
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)
)
}
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(...)
}
)
)
}
我通常会看到条件面板与事件发生一起工作,例如按下按钮或选中复选框等。但在这里,我希望它与我 运行 应用程序时传递的参数一起工作。我试图仅在“输入”参数不为空时显示条件面板,但面板一直出现。这是我试过的代码:
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)
)
}
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(...)
}
)
)
}