在Shiny中的FluidRow中将图居中 [英] Centering a plot within a fluidRow in Shiny

查看:901
本文介绍了在Shiny中的FluidRow中将图居中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a fluidRow with a plot rendered in one of the columns. I would like to know how to center the plot when I have manually specified the plot width via the renderPlot({create plot here}, width = ##) function (thus, it doesn't take up the full width of the column).

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代码:

server.R code:

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)
})


推荐答案

align = center 可以包含在表达式(但不在 plotOutput 内)。
例如

align="center" can be included within the column expression (not within plotOutput though). e.g.

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

这篇关于在Shiny中的FluidRow中将图居中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆