Hide an element (box/tabs) in shiny dashboard

mongofresher picture mongofresher · Oct 9, 2015 · Viewed 9.6k times · Source

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. 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. 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

Answer

DeanAttali picture DeanAttali · Oct 14, 2015

Oskar's answer is correct. But it does not actually use shinyjs, it includes all the JavaScript manually. You can use his answer, but here is a rewrite of his answer using 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)