Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Centre the titlePanel in Shiny?

Tags:

r

shiny

In the Shiny package of R, how can you make the text in the titlePanel be centred on the top of the page?

Here is an example of what I mean

The only code I've used for the titlePanel is:

ui <- fluidPage(
  titlePanel("How to Centre Me??")

When I look at the documentation, the only variables the function takes is:

titlePanel(title, windowTitle = title)

So is it possible to centre the title?

Thanks

like image 791
Sierra Papa Delta Avatar asked Jul 12 '18 05:07

Sierra Papa Delta


People also ask

What is UI and server in R shiny?

Shiny Tutorial A simple shiny app is a directory containing two R scripts, one is ui. R , which controls the layout and appearance of your app, the other is server. R , which contains the instructions that your computer needs to build your app.

How do you add a shiny text box?

You can use tahs$h1() to h6() to add headings, or add text using textOutput(). You can add text using text within quotes(" ").

How do I make text bold in R shiny?

Shiny has many functions that can transform plain text into formatted text. Simply place text inside the h1() function to create a primary header (e.g. a title), h2() for a secondary header, strong() to make text bold, em() to make text italicized, or any of the other formatting functions.

What is shiny UI?

Shiny uses the function fluidPage to create a display that automatically adjusts to the dimensions of your user's browser window. You lay out the user interface of your app by placing elements in the fluidPage function.


3 Answers

In case anyone is still in need of a simple solution:

titlePanel(
    h1("First level title", align = "center")
)
like image 91
BerriJ Avatar answered Nov 15 '22 23:11

BerriJ


You can use column() function.

like this:

fluidPage(
           column(3,offset = 4, titlePanel("How to Centre Me??")) 
           )

where 3 is column width and offset you can adjust according to your requirement.

like image 38
Subhasish1315 Avatar answered Nov 15 '22 21:11

Subhasish1315


With css:

ui <- fluidPage(
  tags$head(
    tags$style(
      ".title {margin: auto; width: 200px}"
    )
  ),
  tags$div(class="title", titlePanel("Centered title"))
)
like image 20
Stéphane Laurent Avatar answered Nov 15 '22 21:11

Stéphane Laurent