gpt4 book ai didi

在 Shiny 的主面板中右对齐元素

转载 作者:行者123 更新时间:2023-12-01 16:19:29 24 4
gpt4 key购买 nike

我有一个 Shiny 的应用程序,左侧有一个侧边栏,我想将 mainPanel 中的绘图向右对齐。我尝试将 style = "align:right" 添加到 mainPanel 中的每个元素,并将我能想到的所有内容包装在 div(..., style = "align:right")。这些都不起作用。

您可以使用this example来自 RStudio 画廊。我想将“表格”选项卡中的输出与右侧对齐。这是 ui.R 的相关部分:

mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Plot", plotOutput("plot")),
tabPanel("Summary", verbatimTextOutput("summary")),
tabPanel("Table", tableOutput("table"))
)
)

最佳答案

您可以将类添加到Table 选项卡。在本例中,我添加了一个 rightAlign 类。 tabPanel("Table", tableOutput("table"), class = 'rightAlign') 然后您可以以任何常用方式设置此选项卡的样式 http://shiny.rstudio.com/articles/css.html对 CSS 使用类似 .rightAlign{float:right;} 的内容。

library(shiny)
runApp(list(
ui = fluidPage(
tags$head(tags$style(".rightAlign{float:right;}")),
titlePanel("Tabsets"),
sidebarLayout(
sidebarPanel(
radioButtons("dist", "Distribution type:",
c("Normal" = "norm",
"Uniform" = "unif",
"Log-normal" = "lnorm",
"Exponential" = "exp")),
br(),
sliderInput("n",
"Number of observations:",
value = 500,
min = 1,
max = 1000)
),
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Plot", plotOutput("plot")),
tabPanel("Summary", verbatimTextOutput("summary")),
tabPanel("Table", tableOutput("table"), class = 'rightAlign')
)
)
)
)
, server = function(input, output) {
data <- reactive({
dist <- switch(input$dist, norm = rnorm, unif = runif,
lnorm = rlnorm, exp = rexp, rnorm)
dist(input$n)
})
output$plot <- renderPlot({
dist <- input$dist
n <- input$n
hist(data(), main=paste('r', dist, '(', n, ')', sep=''))
})
output$summary <- renderPrint({
summary(data())
})
output$table <- renderTable({
data.frame(x=data())
})
}
)
)

enter image description here

关于在 Shiny 的主面板中右对齐元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25387844/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com