有没有办法在闪亮的 tabPanel 中将 R 图居中?

Is there a way to center an R plot within a tabPanel in shiny?

我正在开发一个闪亮的应用程序,我设置图表格式的方式太宽了。我用 width 参数缩短了它们,所以它们看起来很合理,但我不知道如何在选项卡面板中将它们居中(显然 plotOutput 不采用对齐参数)。

 tabsetPanel( 
     tabPanel("Plot1", plotOutput("plot1", width="60%")),
     tabPanel("Plot2", plotOutput("plot2", width="60%"))
   )

我不知道有任何 Shiny 特定方法,但您始终可以使用 css 来设置输出图像的样式。只需将包含以下内容的 tags$style 添加到您的 UI:

"#plot1 img, #plot2 img {
    width: 60%;
    display: block;
    margin-left: auto;
    margin-right: auto;
}"

并从 plotOutput 中删除 width="60%"。排除 width 它只是一个 Bootstrap center-block class。最小 ui 定义可能如下所示:

shinyUI(bootstrapPage(
    tags$head(tags$style(
        type="text/css",
        "#plot1 img, #plot2 img {
            width: 60%;
            display: block;
            margin-left: auto;
            margin-right: auto;
        }"
    )),
    tabsetPanel(
        tabPanel("Plot1", plotOutput("plot1")),
        tabPanel("Plot2", plotOutput("plot2"))
    )
))