是否可以使用 navbarPage 在每个 tabPanel 中添加一个 sidebarPanel 和一个 mainPanel?

Is it possible to add a sidebarPanel and a mainPanel in each tabPanel using navbarPage?

我至少有 2 个单独的应用程序要加入到一个应用程序中。虽然我使用的是 shinyDashboard,但我认为尝试使用 navbarPage.

可能是个好主意

但是,我不知道是否可以用这种新方法做我想做的事情。

为了让您了解情况,这是我的 shinyDashboard 的示例。每个选项卡都有 sidebarPanelmainPanel。我复制了所有选项卡中的信息,但想法是每个选项卡都有不同的内容。

但是,我想使用 navbarPage 来实现它。你知道这是否可能吗?

在此附上我用于 shinyDashboard:

的代码
library(shiny)
library(shinydashboard)
library(shinyWidgets)

ui <- dashboardPage(
  
  dashboardHeader(title = "Basic dashboard"),
  ## Sidebar content
  dashboardSidebar(
    sidebarMenu(
      menuItem("Tab1", tabName = "Tab1", icon = icon("th")),
      menuItem("Tab2", tabName = "Tab2", icon = icon("th")),
      menuItem("Tab3", tabName = "Tab3", icon = icon("th"))
    )
  ),
  
  dashboardBody(
    fluidRow(
      tabItems(
        
        tabItem(tabName = "Tab1",
                sidebarPanel(
                  numericInput("num",
                               "Select a number",
                               min = 1,
                               value = 10),
                  
                  checkboxInput("remove", "Remove...", value = FALSE),
                  sliderInput("slider", "slider", min = 1, max = 30, value=22)
                    
                ),
                mainPanel(
                  plotOutput("plot1")
                )
                
        ),
        tabItem(tabName = "Tab2",
                sidebarPanel(
                  numericInput("num2",
                               "Select a number",
                               min = 1,
                               value = 10),
                  
                  checkboxInput("remove2", "Remove...", value = FALSE),
                  sliderInput("slider2", "slider", min = 1, max = 30, value=22)
                  
                ),
                mainPanel(
                  plotOutput("plot2")
                )
                
        ),
        tabItem(tabName = "Tab3",
                sidebarPanel(
                  numericInput("num3",
                               "Select a number",
                               min = 1,
                               value = 10),
                  
                  checkboxInput("remove3", "Remove...", value = FALSE),
                  sliderInput("slider3", "slider", min = 1, max = 30, value=22)
                  
                ),
                mainPanel(
                  plotOutput("plot3")
                )
        
                
        )
      )
    )
  )
)

server <- function(input, output, session) {
  
  output$plot1 <- renderPlot({
    plot(x=c(1,2,3,4,5,6), y=c(14,3,6,4,56,2))
  })
  
  output$plot2 <- renderPlot({
    plot(x=c(1,2,3,4,5,6), y=c(14,3,6,4,56,2))
  })
  
  output$plot3 <- renderPlot({
    plot(x=c(1,2,3,4,5,6), y=c(14,3,6,4,56,2))
  })
  
}

shinyApp(ui, server)

navbarPage 方法的代码:

library(shinythemes)
library(shiny)

ui <-  fluidPage(theme = shinytheme("flatly"), 
                 navbarPage(
                   
                   collapsible = T,
                   fluid = T,
                   "",
                   tabPanel("Tab 1", "one"),
                   tabPanel("Tab 2", "two"),
                   tabPanel("Tab 3", "three"),
                   )
)

server <- function(input, output, session) {
  
}

shinyApp(ui, server)

非常感谢

您可以使用 sidebarLayout 做到这一点。在这里,我已经为第一个 tabPanel 完成了:

library(shinythemes)
library(shiny)

ui <-  fluidPage(
  theme = shinytheme("flatly"), 
  navbarPage(
    title = "Your App Title", 
    collapsible = TRUE,
    fluid = TRUE,
    
    tabPanel(
      title = "Tab 1", 
      
      sidebarLayout(
        sidebarPanel = sidebarPanel(
          tags$h3(
            "Sidebar Content Here!"
          )
        ), 
        
        mainPanel = mainPanel(
          tags$h3(
            "Main Panel Content Here!"
          )
        )
      )
    ),
    tabPanel(
      title = "Tab 2", 
      "three"
    ),
  )
)

server <- function(input, output, session) {
  
}

shinyApp(ui, server)