shiny提供了几种基本的布局:
tabsetPanel()
和navlistPanel()
函数实现分段布局。navbarPage()
函数实现头部导航布局。示例如下:
ui <- fluidPage(
titlePanel("Hello Shiny!"),
sidebarLayout(
sidebarPanel(
sliderInput("obs", "Number of observations:",
min = 1, max = 1000, value = 500)
),
mainPanel(
plotOutput("distPlot")
)
)
)
使用网格布局实现侧边栏效果:
ui <- fluidPage(
titlePanel("Hello Shiny!"),
fluidRow(
column(4,
wellPanel(
sliderInput("obs", "Number of observations:",
min = 1, max = 1000, value = 500)
)
),
column(8,
plotOutput("distPlot")
)
)
标签页也可以通过position来指定展示位置。
ui <- fluidPage(
titlePanel("Tabsets"),
sidebarLayout(
sidebarPanel(
# Inputs excluded for brevity
),
mainPanel(
tabsetPanel(
tabPanel("Plot", plotOutput("plot")),
tabPanel("Summary", verbatimTextOutput("summary")),
tabPanel("Table", tableOutput("table"))
)
)
)
)
ui <- fluidPage(
titlePanel("Application Title"),
navlistPanel(
"Header A",
tabPanel("Component 1"),
tabPanel("Component 2"),
"Header B",
tabPanel("Component 3"),
tabPanel("Component 4"),
"-----",
tabPanel("Component 5")
)
)
通过navbarPage()
函数可以实现导航栏效果,每个页面都是单独的。
ui <- navbarPage("My Application",
tabPanel("Component 1"),
tabPanel("Component 2"),
tabPanel("Component 3")
)
使用navbarMenu()
函数实现下拉菜单。
ui <- navbarPage("My Application",
tabPanel("Component 1"),
tabPanel("Component 2"),
navbarMenu("More",
tabPanel("Sub-Component A"),
tabPanel("Sub-Component B"))
)
shiny支持自定义样式,将样式文件放在www目录即可。
ui <- fluidPage(theme = "bootstrap.css",
titlePanel("My Application")
# application UI
)
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有