Search code examples
rshinyshinydashboard

How do I achieve this grid and tab structure in R Shiny?


I have the following grid and tab structure in a Shiny app.

Desired result

What I want to get to is to have a different tabsetPanel for every Dataset that I choose in the left column.

So basically I would have a "master" left column - that could be hidden if the user wants so - and a central panel with different tabs for whichever dataset one selects on the left column.

This is the current code:

library(shiny)
library(plotly)
library(gridlayout)
library(bslib)

ui <- grid_page(
  layout = c(
    "header  header",
    "sidebar Impost"
  ),
  row_sizes = c(
    "40px",
    "1fr"
  ),
  col_sizes = c(
    "165px",
    "1fr"
  ),
  gap_size = "1rem",
  grid_card(
    area = "sidebar",
    card_header("DATASET Simulator"),
    card_body(
      selectInput(
        inputId = "dataset",
        label = "DATASET",
        choices = list(
          "Dataset 1" = "Dataset 1",
          "Dataset 2" = "Dataset 2",
          "Dataset 3" = "Dataset 3"
        ),
        selected = "Dataset 1",
        width = "100%"
      ),
      em("Select the type of dataset you want to simulate.")
    )
  ),
  grid_card_text(
    area = "header",
    content = "Dataset Simulation Project",
    alignment = "start",
    is_title = FALSE
  ),
  grid_card(
    area = "Impost",
    full_screen = TRUE,
    card_header("Dataset 1"),
    card_body(
      tabsetPanel(
        nav_panel(title = "Parameters"),
        nav_panel(title = "Results 1"),
        nav_panel(title = "Results 2")
      )
    )
  )
)

server <- function(input, output) { 
}

shinyApp(ui, server)

I have checked the Mastering Shiny book, lots of internet sources, and used the new Shiny UI Editor but I am at a loss on how to achieve it.


Solution

  • Thank you to both YBS and Gonzalo T F. Finally I mixed your answers to create the following body through shinydashboard and conditional panels:

    dashboardBody(
    #dataset 1
    conditionalPanel(condition = "input.dataset == 'dataset1'",
                     card_header('Data 1') %>% h2,
                     card_body(
                       tabsetPanel(
                         id = "tabs1",
                         type = c("tabs"),
                         nav_panel(title = "P 1"),
                         nav_panel(title = "R 1"),
                         nav_panel(title = "G 1")
                         )
                       )
                     ),
    #dataset 2
    conditionalPanel(condition = "input.dataset == 'dataset2'",
                     card_header('Data 2') %>% h2,
                     card_body(
                       tabsetPanel(
                         id = "tabs1",
                         type = c("tabs"),
                         nav_panel(title = "P 2"),
                         nav_panel(title = "R 2"),
                         nav_panel(title = "G 2")
                         )
                       )
                     )
    )