gpt4 book ai didi

r - 在侧边栏菜单项之一上方添加空间

转载 作者:行者123 更新时间:2023-12-03 14:06:38 29 4
gpt4 key购买 nike

我想在侧边栏菜单项之一上方添加空间。例如,下面示例中的“小部件”应显示在侧边栏下方的页面底部(意味着菜单顶部应有空间)。我试着用 tags$div(style = "margin-top: 50px;", 做这件事但没有得到想要的输出。

library(shinydashboard)
library(shiny)

ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(
sidebarMenu(
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
menuItem("Widgets", tabName = "widgets", icon = icon("th"))
)
),
dashboardBody(
tabItems(
# First tab content
tabItem(tabName = "dashboard",
fluidRow(
box(plotOutput("plot1", height = 250)),

box(
title = "Controls",
sliderInput("slider", "Number of observations:", 1, 100, 50)
)
)
),

# Second tab content
tabItem(tabName = "widgets",
h2("Widgets tab content")
)
)
)
)

server <- function(input, output) {
set.seed(122)
histdata <- rnorm(500)

output$plot1 <- renderPlot({
data <- histdata[seq_len(input$slider)]
hist(data)
})
}

shinyApp(ui, server)

最佳答案

你可以使用这个 CSS:

css <- "
.sidebar-menu li:not(:last-child) {
margin-bottom: 200px;
}
"

ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(
sidebarMenu(
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
menuItem("Widgets", tabName = "widgets", icon = icon("th"))
)
),
dashboardBody(
tags$head(
tags$style(HTML(css))
),
tabItems(
......

关于r - 在侧边栏菜单项之一上方添加空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63276801/

29 4 0