【问题标题】:Centering a plot within a fluidRow in Shiny在 Shiny 的流体行中将绘图居中
【发布时间】:2014-09-28 14:40:09
【问题描述】:

我有一个fluidRow,其中一列中呈现了一个绘图。我想知道当我通过 renderPlot({create plot here}, width = ##) 函数手动指定绘图宽度时如何使绘图居中(因此,它不占用列的整个宽度) .

ui.R 代码:

setwd("C:/Users/Nate/Documents/R Working Directory/appFolder/example")
shinyUI(fluidPage(
titlePanel("Test"),
sidebarLayout(
sidebarPanel(
p('stuff here')
  ),
mainPanel(
tabsetPanel(id = 'tabs1',
          tabPanel("main",
                   fluidRow(
                     column(8,
                            plotOutput('plot1')),
                     column(4,
                            p('2nd column'))),
                   fluidRow(
                   p("2nd row of viewing area"))
                   ),

          tabPanel("second",
                   p("main viewing area")),
          tabPanel("third",
                          p('main viewing area')
                   )
))
)
))

server.R 代码:

shinyServer(function(input, output, session) {
output$text1 = renderText({
paste("text output")
})
output$plot1 = renderPlot({
x = runif(10,0,10)
y = rnorm(10)
plot(x,y)
}, width = 300)
})

【问题讨论】:

    标签: r plot shiny centering


    【解决方案1】:

    align="center" 可以包含在 column 表达式中(但不能包含在 plotOutput 中)。 例如

    fluidRow(
      column(8, align="center",
        plotOutput('plot1')
      )
    )
    

    【讨论】:

    • fluidRow 中只有一个元素时,它缺少offset 来实际工作
    【解决方案2】:

    您可以将align="center" 用作plotOutput() 函数的一部分。所以你的 ui.R 会这样:

    ui.R

    setwd("C:/Users/Nate/Documents/R Working Directory/appFolder/example")
    shinyUI(fluidPage(
    titlePanel("Test"),
    sidebarLayout(
    sidebarPanel(
    p('stuff here')
      ),
    mainPanel(
    tabsetPanel(id = 'tabs1',
              tabPanel("main",
                       fluidRow(
                         column(8,
                                plotOutput('plot1',align="center")),
                         column(4,
                                p('2nd column'))),
                       fluidRow(
                       p("2nd row of viewing area"))
                       ),
    
              tabPanel("second",
                   p("main viewing area")),
          tabPanel("third",
                          p('main viewing area')
                       )
    ))
    )
    ))
    

    【讨论】:

      猜你喜欢
      • 2011-06-22
      • 2019-01-22
      • 1970-01-01
      • 1970-01-01
      • 2017-01-30
      • 2014-08-09
      • 1970-01-01
      • 2021-12-14
      • 1970-01-01
      相关资源
      最近更新 更多