我在设置我闪亮的应用程序的布局上遇到了一些困难。在尝试了几种不同的选择之后,对我来说最适合我的就是navbarPage。虽然,我设法解决了我的大部分问题(在堆栈溢出的帮助下),但我还是陷入了其中一个问题。基本上,我有一个有许多列的表,它最终总是大于包含该表的wellPanel。
下面是一些代码来说明这个问题:
require(shiny)
require(shinythemes)
side_width <- 5
sidebar_panel <-
sidebarPanel(
width = side_width,
radioButtons("Radio1",
label = h4("Radio label 1"),
choices = list("Europe" = "EU",
"USA" = "US"),
selected = "EU"),
hr()
br()
radioButtons("Radio 2",
label = h4("Radio label 2"),
choices = list("Annual" = 1, "Monthly" = 12),
selected = 1)
)
main_panel <- mainPanel(
width = 12 - side_width,
wellPanel(
h5(helpText("Figure 1: ..."))
),
wellPanel(
h5(helpText("Table 1: ..."))
),
wellPanel(
h5(helpText("Table 2: ..."))
),
wellPanel(
fluidRow(
column(12,
h5(helpText("Table 3: ..."))
)
)
)
)
# user interface
ui <- shiny::navbarPage("testing shiny",
tabPanel("Tab1",
sidebarLayout(
sidebarPanel = sidebar_panel,
mainPanel = main_panel,
position = "left")
),
tabPanel("Tab2",
verbatimTextOutput("summary")
),
tags$style(type="text/css", "body {padding-top: 70px;}"),
theme=shinytheme("cosmo"),
position ="fixed-top"
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)
运行代码时,您将看到当前的布局。所有的一切都会好,如果不是因为巨大的宽表3,其中一半总是在wellPanel之外。
我的问题是,是否可以将wellPanel扩展到左侧,使其占据布局的整个宽度?
任何指示都会受到高度赞赏。干杯
发布于 2019-10-27 15:43:53
fluidRow和列函数不会在wellPanel/mainPanel中执行任何操作--您希望将这个特定的wellPanel作为自己的fluidRow与侧栏布局分开。
此外,如果您的表是在DT包中创建的,您可以将scrollX=TRUE添加到呈现选项中,这样如果表太大,它就会添加滚动条。
require(shiny)
require(shinythemes)
side_width <- 5
# user interface
ui <- navbarPage(
"testing shiny",
tabPanel("Tab1",
sidebarLayout(position = "left",
sidebarPanel(width = side_width,
radioButtons("Radio1",
label = h4("Radio label 1"),
choices = list("Europe" = "EU",
"USA" = "US"),
selected = "EU"),
hr(),
br(),
radioButtons("Radio 2",
label = h4("Radio label 2"),
choices = list("Annual" = 1, "Monthly" = 12),
selected = 1)),
mainPanel(
width = 12 - side_width,
wellPanel(
h5(helpText("Figure 1: ..."))
),
wellPanel(
h5(helpText("Table 1: ..."))
),
wellPanel(
h5(helpText("Table 2: ..."))
)
)
),
fluidRow(
column(12,
wellPanel(
h5(helpText("Table 3: ..."))
)
)
)
),
tabPanel("Tab2",
verbatimTextOutput("summary")),
tags$style(type = "text/css", "body {padding-top: 70px;}"),
theme = shinytheme("cosmo"),
position = "fixed-top"
)
https://stackoverflow.com/questions/58583660
复制