1

I would like to open a second dashboard by pressing the action button on the first dashboard. I was able to do that using the code below but the dashboards are connected to each other. E.g. if I close the sidebar on the second dashboard, the sidebar of the first one closes, too.

This is the server.R file:

function(input, output, session) {
  # some more code

  # react to clicking on button show2
  observeEvent(input$show2, {
      # here is some more code
      showModal(settngsModal())
  })

  settngsModal <- function() {
    modalDialog(

      withTags({ 
        dashboardPage(
          dashboardHeader(
            title = "Second Dashboard"
          ),
          dashboardSidebar(
            sidebarMenu(
              menuItem("Widgets", tabName = "widgets", icon = icon("th"))
            )),
          dashboardBody(
            tabItem(tabName = "widgets",
                    h1("Widgets tab content")
            )
          )
        )
      }),
      title = "Settings",
      fade = TRUE)
  }
}

This is the ui.R file:

dashboardPage(

    dashboardHeader(
      title = "First dashboard"
    ),

    dashboardSidebar(collapsed = TRUE,sidebarMenu()),
    dashboardBody(),

      h1('Headline'),

      actionButton("show2", "Show second dashboard", size = 'lg')
    )
)

Is it possible to have an "independent" dashboard?

Maybe even having two dashboards that can be used side by side (because now the second dashboard is a popup and the first dashboard can only be used if the second one is closed)?

MaMo
  • 569
  • 1
  • 10
  • 27

1 Answers1

1

You could use shinyjs to toggle between the two dashBoardPage tags.

Below is an example of switching between two Dashboards, there's a decent issue thread around rendering UI dashboardPage elements reactively.


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

ui <-  tagList(
  useShinyjs(),

  div(id = "dashboard_two",
      style = "display:none",
      dashboardPage(
        dashboardHeader(
          title = "Second dashboard"
        ),
        dashboardSidebar(collapsed = TRUE,sidebarMenu()),
        dashboardBody(fluidRow(actionButton("show1", "Show first dashboard")),
                      fluidRow(box(title = "Dash Two", height = 300, "Testing Render")) )
      )
  ),

  div(id = "dashboard_one",
      style = "display:none",
      dashboardPage(

        dashboardHeader(
          title = "First dashboard"
        ),
        dashboardSidebar(collapsed = TRUE, sidebarMenu()),
        dashboardBody(actionButton("show2", "Show second dashboard")
                      )
      )
  )
)


server <- function(input, output) {
  shinyjs::show("dashboard_one")
  observeEvent({ input$show1; input$show2}, {
    shinyjs::toggle("dashboard_one")
    shinyjs::toggle("dashboard_two")
  })
}

shinyApp(ui, server)
RK1
  • 2,384
  • 1
  • 19
  • 36
  • It does not work for me, I get the error: could not find function "taglist". If it does work for you, can you tell me how to fix this? Thanks! – MaMo Sep 18 '19 at 15:03
  • That's strange, are you sure you're loading all the `shiny` libraries above ? It's just a [function](https://www.rdocumentation.org/packages/shiny/versions/0.14.2/topics/tag) shipped with `Shiny` – RK1 Sep 18 '19 at 15:19
  • Make sure you wrote `tagList` and not `taglist` :) – RK1 Sep 18 '19 at 15:33
  • Yes, I even copied and pasted your simple example and reinstalled Rtools and all the libraries you used. Every time I get: ```Warning: Error in taglist: could not find function "taglist" [No stack trace available]``` – MaMo Sep 19 '19 at 07:01
  • ok, perfect. It was a problem with the location of the R file. Thank you so much! – MaMo Sep 19 '19 at 07:07