简体   繁体   English

在闪亮的仪表板中隐藏元素(框/标签)

[英]Hide an element (box/tabs) in shiny dashboard

I have a shiny dashboard which has a just a single text box on the landing page. 我有一个闪亮的仪表板,在登录页面上只有一个文本框。 The user enters an emailid which displays relevant data. 用户输入显示相关数据的emailid。 This works fine. 这很好用。 However I need a box/ tab Panel that greets the user on reaching the page and disappears when the user begins to enter text(emailid) in the text input. 但是我需要一个盒子/选项卡面板,当用户开始在文本输入中输入文本(emailid)时,它会在到达页面时迎接用户并消失。 Is this possible? 这可能吗?

output$introbox=renderUI(box(h3("Welcome to the page. Please enter your email id to proceed")),
                                conditionalPanel(condition=input.emailid=="")

The box is displayed on landing on the page but doesn't disappear on entering text. 该框显示在页面的着陆上,但在输入文本时不会消失。

Appreciate any help. 感谢任何帮助。 Thanks 谢谢

Oskar's answer is correct. 奥斯卡的回答是正确的。 But it does not actually use shinyjs, it includes all the JavaScript manually. 但它实际上并不使用shinyjs,而是手动包含所有JavaScript。 You can use his answer, but here is a rewrite of his answer using shinyjs 你可以使用他的答案,但这里是使用shinyjs重写他的答案

library(shiny)
library(shinydashboard)
library(shinyjs)

ui <-dashboardPage(
  dashboardHeader(),
  dashboardSidebar(
  ),
  dashboardBody(
    useShinyjs(),
    div(id = "greetbox-outer",
      box( id ="greetbox",
           width  = 12, 
           height = "100%",
           solidHeader = TRUE, 
           status = "info",
           div(id="greeting", "Greeting here") 
      )
    ),
    box( id ="box",
         width  = 12, 
         height = "100%",
         solidHeader = TRUE, 
         status = "success",

         textInput("txtbx","Enter text: ")
    )
      )
    )

server <- shinyServer(function(input, output, session) {
  observeEvent(input$txtbx,{
    if (input$txtbx == "") return(NULL)
    hide(id = "greetbox-outer", anim = TRUE)
    print(input$txtbx)
  })
})

shinyApp(ui = ui, server = server) 

Yes this is possible and as daattali sugested shinyjs can help you with some standard Javascript tasks. 是的,这是可能的,因为daattali sugested shinyjs可以帮助您完成一些标准的Javascript任务。

If you want to hide the shinydashboard box element you have to (from what I know) use some custom Javascript like this: 如果你想隐藏shinydashboard box元素你必须(据我所知)使用一些自定义的Javascript,如下所示:

library(shiny)
library(shinydashboard)
library(shinyjs)

ui <-dashboardPage(
  dashboardHeader(),
  dashboardSidebar(
  ),
  dashboardBody(
    tags$head(
      tags$script(
        HTML("
        Shiny.addCustomMessageHandler ('hide',function (selector) {
          $(selector).parent().slideUp();
        });"
        )
      )
    ),
    box( id ="greetbox",
         width  = 12, 
         height = "100%",
         solidHeader = TRUE, 
         status = "info",
         div(id="greeting", "Greeting here") 
    ),
    box( id ="box",
         width  = 12, 
         height = "100%",
         solidHeader = TRUE, 
         status = "success",

         textInput("txtbx","Enter text: ")
    )
  )
)

server <- shinyServer(function(input, output, session) {
  observeEvent(input$txtbx,{
    if (input$txtbx == "") return(NULL)
    session$sendCustomMessage (type="hide", "#greetbox")
    print(input$txtbx)
  })
})

shinyApp(ui = ui, server = server) 

The html layout for the box looks like: 该框的html布局如下所示:

<div class="box box-solid box-info">
    <div class="box-body" id="greetbox">
        <!-- Box content here -->
    </div>
</div>

And since we want to hide the whole box we have to hide the parent element to the id set in the box function, hence the jQuery snippet. 由于我们想要隐藏整个框,我们必须将父元素隐藏到框函数中的id集,因此jQuery片段。

I had a similar issue, and my problem was with box() : if I changed box() to div() , then the show/hide options worked perfectly. 我有一个类似的问题,我的问题是box() :如果我将box()更改为div() ,那么show / hide选项工作得很好。

This solution is simpler, yet not so elegant as modifying the tags. 这个解决方案更简单,但不如修改标签那么优雅 Simply wrap your box() on a div() like this: 只需将你的box()包装在div()如下所示:

div(id = box1, box(...))
div(id = box2, box(...))

Then, you call to show/hide using the div 's id. 然后,使用div的id调用show / hide。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM