Centering a plot within a fluidRow in Shiny

Nate Gilbraith picture Nate Gilbraith · Aug 5, 2014 · Viewed 29k times · Source

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 code:

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

Answer

Ewen picture Ewen · Oct 21, 2014

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

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