是否可以使用navbarPage在每个选项卡面板中添加一个侧边栏面板和一个主面板? [英] Is it possible to add a sidebarPanel and a mainPanel in each tabPanel using navbarPage?

查看:0
本文介绍了是否可以使用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)

这篇关于是否可以使用navbarPage在每个选项卡面板中添加一个侧边栏面板和一个主面板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆