gpt4 book ai didi

r - 隐藏/显示输出 Shiny R

转载 作者:行者123 更新时间:2023-12-04 12:04:07 25 4
gpt4 key购买 nike

我试图找出每次用户更改widjets中的某些内容时如何显示和隐藏我的输出,如图形和表格。例如,我的变量“性别”有一个 slider 输入,有两个选择:男性和女性。我还有一个按钮,当用户点击它时执行估计。每次当用户在不同的widjets之间改变至少一个选择时,我想隐藏输出。例如,经过一次估计后,用户决定只更改教育水平,当用户单击 slider 输入框时,我想隐藏以前的结果。

我尝试使用 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")
}
})

谢谢你。

最佳答案

这里的其他答案似乎没有提供正确/完整的答案。解决方案其实很简单。
您需要使用 outputOptions(output, 'show', suspendWhenHidden = FALSE)下面是一个示例代码,它显示了 conditionalPanel 中的文本。如果下拉选择为 2,如果为 1,则隐藏。

  library(shiny)

ui <- fluidPage(
selectInput("num", "Choose a number", 1:2),

conditionalPanel(
condition = "output.show",
"The selected number is 2 so this text is displayed. Change it back to 1 to hide."
)

)

server <- function(input, output, session) {
output$show <- reactive({
input$num == 2 # Add whatever condition you want here. Must return TRUE or FALSE
})

outputOptions(output, 'show', suspendWhenHidden = FALSE)
}

shinyApp(ui = ui, server = server)

关于r - 隐藏/显示输出 Shiny R,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35136029/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com