隐藏/显示输出闪亮R [英] Hide/show outputs Shiny R

查看:21
本文介绍了隐藏/显示输出闪亮R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试了解如何在每次用户更改小部件中的某些内容时显示和隐藏图形和表格等输出。例如,我有一个名为"Gender"的变量的滑块输入,有两个选项:男性和女性。我还有一个按钮,当用户单击它时执行评估。每次用户在不同的小部件之间更改至少一个选择时,我都希望隐藏输出。例如,在一次评估之后,用户决定只更改教育程度,而当用户单击SliderInput框时,我想隐藏以前的结果。

我尝试使用R包shinyjs和函数Hide/Show,但它们不能用于输出。

您知道如何在不使用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")
      }      
})

谢谢您。

推荐答案

正如迪特尔在您需要使用的评论中提到的conditionalPanel。例如,在您的ui.R中,而不是

plotOutput('simulationChange')

使用

conditionalPanel("output.show", plotOutput('simulationChange'))

并在您的服务器中。R添加以下内容:

values <- reactiveValues()
values$show <- TRUE

observe({
    input$gender
    input$age
    input$birthplace
    input$education
    values$show <- FALSE
})

output$show <- reactive({
    return(values$show)
})

另外,单击您的按钮时,不要忘记更改values$show

observeEvent(input$button, {
    ...
    values$show <- TRUE
})

这篇关于隐藏/显示输出闪亮R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆