使 conditionalPanel 与 R 闪亮 Golem 包中的输入参数一起工作

如何解决使 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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?