how to align tabsetpanel "pills" center in R shiny

Viewed 99

I am trying to center-align tabsetpanel "pills" on shiny, but it alwais get on left position. Here is the code example, anyone knows how to align this buttons or pills center?

library(shiny)
ui <- fluidPage(
  tabPanel(title = "Hello world", value = "HB", 
           tabsetPanel(id="subtabs", type="pills", 
                       tabPanel(title = "TAB 1", value = "ILPF", 
                                br(),
                                h4("I like Pink floyd, my favourite album is 'The dark side of the moon'", style = "color:grey", align = "center"),
                                br()
                       ),
                       tabPanel(title = "TAB 2", value = "FS",  
                                br(),
                                h4("But my favourite song is 'Shine on you crazy diamond'", style = "color:grey", align = "center"),
                                br()
                                )
                       )
           )
)

server <- function(input, output, session) {}
shinyApp(ui = ui, server = server)

The pills should be in the middle of the page

1 Answers

You can do so by adding some CSS to your app. tags$style('ul.nav-pills{display: flex !important;justify-content: center !important;}') does the trick.

library(shiny)
ui <- fluidPage(
  tags$head(
    tags$style('
    ul.nav-pills{
      display: flex !important;
      justify-content: center !important;
    }')
  ),
  tabPanel(title = "Hello world", value = "HB", 
           tabsetPanel(id="subtabs", type="pills", 
                       tabPanel(title = "TAB 1", value = "ILPF", 
                                br(),
                                h4("I like Pink floyd, my favourite album is 'The dark side of the moon'", style = "color:grey", align = "center"),
                                br()
                       ),
                       tabPanel(title = "TAB 2", value = "FS",  
                                br(),
                                h4("But my favourite song is 'Shine on you crazy diamond'", style = "color:grey", align = "center"),
                                br()
                       )
           )
  )
)

server <- function(input, output, session) {}
shinyApp(ui = ui, server = server)

enter image description here

Related