Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Centering a plot within a fluidRow in Shiny

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)
})
like image 630
Nate Gilbraith Avatar asked Aug 05 '14 19:08

Nate Gilbraith


1 Answers

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

fluidRow(
  column(8, align="center",
    plotOutput('plot1')
  )
)
like image 174
Ewen Avatar answered Nov 13 '22 00:11

Ewen