【发布时间】:2016-05-10 05:29:16
【问题描述】:
我正在尝试了解如何在每次用户更改 widjet 中的某些内容时显示和隐藏我的输出,例如图形和表格。例如,我的变量“性别”有一个滑块输入,有两个选择:男性和女性。我还有一个按钮,当用户点击它时执行估计。每次当用户在不同的widjets之间改变至少一个选择时,我想隐藏输出。例如,经过一次估计后,用户决定只更改教育水平,当用户单击滑块输入框时,我想隐藏以前的结果。
我尝试使用 R 包 shinyjs 和隐藏/显示功能,但它们不适用于输出。
你知道如何在不使用 shinyjs 包的情况下做到这一点吗?
这是我的代码的一部分:
shinyUI(fluidPage(
sidebarLayout(
fluidRow(
column(4, wellPanel(
fluidRow(
column(5,selectInput("gender",
label = div("Sexe",style = "color:royalblue"),
choices = list("Male", "Female"),
selected = "Female")),
# other different widjets..
column(8, plotOutput('simulationChange')),
column(4, tableOutput('simulationChangeTable'),
tags$style("#simulationChangeTable table {font-size:9pt;background-color: #E5E4E2;font-weight:bold;margin-top: 121px; margin-left:-30px;overflow:hidden; white-space:nowrap;text-align:left;align:left;}",
media="screen",
type="text/css"),
fluidRow(
column(6, tableOutput('simulationChangeEsperance'),
tags$style("#simulationChangeEsperance table {font-size:9pt;background-color: #E5E4E2;font-weight:bold;margin-top: -10px; margin-left:-30px;overflow:hidden; white-space:wrap;word-break: break-word;width:173px;text-align:left;}"))
)
)
)
)
)
))
shinyServer(function(input, output, session) {
# part of my server.R code
observe({
if (input$gender|input$age|input$birthplace|input$education){
shinyjs::hide("simulationChange")
shinyjs::hide("simulationChangeTable")
shinyjs::hide("simulationChangeEsperance")
}
})
谢谢。
【问题讨论】:
-
看看在 ui.r 中使用的 conditionalPanel
-
我是 shinyjs 的作者,它确实适用于输出。我尝试运行您的代码以查看问题所在,但您提供的代码错误太多,难以处理。如果你能提供一段更短的能够运行的代码,我就能明白为什么你的 shinyjs::hide() 不起作用
-
嗨,很高兴认识你。谢谢您的回答。我有很长的 server.R 脚本和 ui.R 脚本。另外,我不能发布所有内容,因为我不被允许。这就是为什么我写了一部分代码当然不能单独工作。