Shiny Dashboard布局求助:如何让Plot与设置栏并排显示?
解决方案
你的问题出在布局结构上:当前代码里把绘图放在了宽度为12的column中,占满了整行空间,导致设置菜单只能被挤到下一行。要实现设置菜单与绘图并排,只需将两者放在同一fluidRow的不同column里,合理分配宽度比例即可。
修改后的核心代码
body <- dashboardBody( tabItems( tabItem(tabName = "Dimension-Plot", fluidPage( fluidRow( # 绘图区域:占8列,可根据需求调整宽度 column(width = 8, plotOutput("plot", click = "plot_click", width = "100%", height = "300px")), # 设置菜单区域:占4列,和绘图列宽度总和为12 column(width = 4, # sidebarPanel宽度设为12,填满所在column空间 sidebarPanel(width = 12, selectInput("Dim1", h3("Settings"), choices = list("True" = TRUE, "False" = FALSE), selected = 1), selectInput("Dim2", label = "Seperate Plots", choices = list("Null" = "Null", "Sample" = "orig.ident", "Condition" = "Type", "Clusters" = "RNA_snn_res.1"), selected = 2), selectInput("Dim3", label = "Group Plots", choices = list("Sample" = "orig.ident", "Condition" = "Type", "Clusters" = "RNA_snn_res.1"), selected = 3), numericInput("Dim4", label = "Label Size", value = 4, min = 1, max = 20), numericInput("Dim5", label = "Point Size", value = 4, min = 1, max = 20), selectInput("Dim6", label = "Label Color", choices = list("Black" = "black", "Blue" = "blue", "Red" = "red"), selected = 1) ) ) ) ) ), # 其他tabItem保持不变 tabItem(tabName = "Violin-Plot", h2("Widgets tab content") ), tabItem(tabName = "Dot-Plot", h2("Widgets tab content") ), tabItem(tabName = "Feature-Plot", h2("Widgets tab content") ), tabItem(tabName = "Average-Expression", h2("Widgets tab content") ), tabItem(tabName = "Differential-Expression", h2("Widgets tab content") ) ))
关键调整说明
- 将绘图和设置菜单的
column放在同一个fluidRow下,确保它们在同一行显示 - 调整两个
column的width参数(总和需为12):比如绘图占8列、设置占4列,你也可以根据需求改成7和5、9和3等比例 - 设置
sidebarPanel(width = 12),让设置菜单填满所在column的空间,避免留白
内容的提问来源于stack exchange,提问作者Syed Ali
相关产品推荐
相关产品推荐

