ShinyDashboard:长 sidebarPanel 导致 dashboardBody 内的 MainPanel 出现问题
ShinyDashboard: Long sidebarPanel causes problems to the MainPanel inside the dashboardBody
我正在尝试使用 shinydashboard
包创建一个闪亮的应用程序。
在下面的示例中,您有一个我的应用程序示例,您可以在其中发现我有一个很长的侧边栏面板,其中有很多选项,然后是一个主面板,我想在其中显示情节和 table 下面。
问题是...由于边栏很长,面板和 table 没有很好地显示,灰色背景直到 table 结束才覆盖,显示黑色背景。
有没有可能把灰色的黑底延长,覆盖所有的东西?
我看过这个 但他们没有在仪表板正文中使用 sidebarPanel
命令。
代码:
library(shiny)
library(shinydashboard)
library(magrittr)
library(DT)
new_choices <- setNames(names(mtcars), names(mtcars))
ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
## Sidebar content
dashboardSidebar(
sidebarMenu(
menuItem("Plot", tabName = "Plot", icon = icon("th"))
)
),
dashboardBody(
tabItems(
tabItem(tabName = "Plot",
sidebarPanel(
selectInput("list", "Choose",
choices = new_choices),
radioButtons("List_type", "Type of list",
c("List 1" = "1",
"List 2" = "2")),
checkboxInput("show", "Do you want.... ?",
value = FALSE),
radioButtons("OptionToDo", "What do you want to do?",
c("Option 1" = "opt1",
"Option 2" = "opt2")),
conditionalPanel(
condition = "input.OptionToDo == 'opt1'",
actionButton("view", "View")
),
# Only show this panel if the user has selected to see the distribution. The user will be able to change the type of distribution.
conditionalPanel(
condition = "input.OptionToDo == 'opt2'",
selectInput(
"option2", "Options:",
c("Histogram" = "histogram", "Boxplot" = "boxplot", "Densigram" = "densigram")
),
),
hr(),
h4(strong("You can write...")),
textInput(inputId = "title", "You can write the title:", value = "This is "),
textInput(inputId = "title2", "You can write the title 2:", value = "This is "),
textInput(inputId = "title3", "You can write the title 3:", value = "This is "),
hr(),
h4(strong("You can change some parameters:")),
numericInput(inputId = "max", label = "Max:", value = 1e40),
numericInput(inputId = "min", label = "Min:", value = -50),
checkboxInput("change_2", "change2", value = TRUE),
checkboxInput("change_3", "Change3", value = TRUE),
checkboxInput("change_4", "Change4", value = TRUE),
checkboxInput("change_5", "Change5", value = TRUE),
checkboxInput("change_6", "Change6", value = TRUE),
checkboxInput("change_7", "Change7", value = TRUE),
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("plot2"),
dataTableOutput("table")
)
)
)
)
)
server <- function(input, output, session) {
x <- 4
y<- 10
output$plot2 <- renderPlot({
plot(x,y)
})
output$table <- renderDataTable({
mtcars
})
}
shinyApp(ui, server)
有谁知道我应该怎么做才能修复它?
非常感谢。
正如您 link 所建议的答案,您需要将 tabItems
包裹在 fluidRow
:
dashboardBody(
fluidRow(
tabItems(
...
)
)
)
我正在尝试使用 shinydashboard
包创建一个闪亮的应用程序。
在下面的示例中,您有一个我的应用程序示例,您可以在其中发现我有一个很长的侧边栏面板,其中有很多选项,然后是一个主面板,我想在其中显示情节和 table 下面。
问题是...由于边栏很长,面板和 table 没有很好地显示,灰色背景直到 table 结束才覆盖,显示黑色背景。
有没有可能把灰色的黑底延长,覆盖所有的东西?
我看过这个 sidebarPanel
命令。
代码:
library(shiny)
library(shinydashboard)
library(magrittr)
library(DT)
new_choices <- setNames(names(mtcars), names(mtcars))
ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
## Sidebar content
dashboardSidebar(
sidebarMenu(
menuItem("Plot", tabName = "Plot", icon = icon("th"))
)
),
dashboardBody(
tabItems(
tabItem(tabName = "Plot",
sidebarPanel(
selectInput("list", "Choose",
choices = new_choices),
radioButtons("List_type", "Type of list",
c("List 1" = "1",
"List 2" = "2")),
checkboxInput("show", "Do you want.... ?",
value = FALSE),
radioButtons("OptionToDo", "What do you want to do?",
c("Option 1" = "opt1",
"Option 2" = "opt2")),
conditionalPanel(
condition = "input.OptionToDo == 'opt1'",
actionButton("view", "View")
),
# Only show this panel if the user has selected to see the distribution. The user will be able to change the type of distribution.
conditionalPanel(
condition = "input.OptionToDo == 'opt2'",
selectInput(
"option2", "Options:",
c("Histogram" = "histogram", "Boxplot" = "boxplot", "Densigram" = "densigram")
),
),
hr(),
h4(strong("You can write...")),
textInput(inputId = "title", "You can write the title:", value = "This is "),
textInput(inputId = "title2", "You can write the title 2:", value = "This is "),
textInput(inputId = "title3", "You can write the title 3:", value = "This is "),
hr(),
h4(strong("You can change some parameters:")),
numericInput(inputId = "max", label = "Max:", value = 1e40),
numericInput(inputId = "min", label = "Min:", value = -50),
checkboxInput("change_2", "change2", value = TRUE),
checkboxInput("change_3", "Change3", value = TRUE),
checkboxInput("change_4", "Change4", value = TRUE),
checkboxInput("change_5", "Change5", value = TRUE),
checkboxInput("change_6", "Change6", value = TRUE),
checkboxInput("change_7", "Change7", value = TRUE),
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("plot2"),
dataTableOutput("table")
)
)
)
)
)
server <- function(input, output, session) {
x <- 4
y<- 10
output$plot2 <- renderPlot({
plot(x,y)
})
output$table <- renderDataTable({
mtcars
})
}
shinyApp(ui, server)
有谁知道我应该怎么做才能修复它?
非常感谢。
正如您 link 所建议的答案,您需要将 tabItems
包裹在 fluidRow
:
dashboardBody(
fluidRow(
tabItems(
...
)
)
)