3
votes

is there any way to show all of the contents in the mainPanel only when the user clicks the action button? ive been searching the internet for awhile for the answer but couldn't really find an answer. i know i can use hidden - it works on smaller elements inside the mainPanel, such as showing a picture on click but doesn't work on the whole mainPanel itself. any suggestions? finding a way to wrap the whole main panel inside a hidden instead of each element in the mainPanel wrapped in a hidden would be easier i think but i can't seem to find a way to make it work.

in dashboard body:

fluidRow(
  column(12, actionButton("analyze", "Fetch Data!", width = "100px"))), 

hidden(    
     mainPanel(  
        hidden( (htmlOutput("artistpic")), // this works fine & shows on button click
        infoBoxOutput("approvalBox"))     
            )),

server:

  pic <- eventReactive(input$analyze2, {
      print(get_id_picture()[3])
      url = toString(get_id_picture()[3])
      print(url)
      url 
  })
  output$artistpic <- renderText({c('<img src="',pic(),'"width="17%" height="17%">')})
1

1 Answers

3
votes

This is easy with shinyjs.

Just surround mainPanel() with a div() tag so that you can use it's id for toggling it's visability and start the app with the div tag hidden using hidden() like in the following example:

# ui.R

fluidPage(
  useShinyjs(),
  actionButton("toggle.main.button", "Toggle Main"),
  div(id = "main",
    mainPanel(
      p("This paragraph is in main."),
      p("This one too!")
    )
  ) %>% shinyjs::hidden()
)

# server.R

library(shinyjs)

function(input, output, session) {

  # Toggling visability of main on button click.
  observeEvent(input$toggle.main.button, {
    shinyjs::toggle("main")
  })

}