Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Some right-aligned tabPanels in shiny

Tags:

css

r

shiny

Using navbarPage I would like to have some tabPanels to be right-aligned while the rest of tabPanels and navbarMenus to be left-aligned:

So, instead of this

library(shiny)    
ui =  tagList(
  navbarPage(
    title = "My app",
    navbarMenu("Left1",
               tabPanel("Subleft11"),
               tabPanel("Subleft12")),
    tabPanel("Left2"),
    tabPanel("Left3"),
    tabPanel("Right1"),
    tabPanel("Right2")
  )
)

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

shinyApp(ui, server)

enter image description here

I would like to get something like this:

enter image description here

Solution from GyD works fine for tabsetPanel but I was not able to adapt it to navbarPage. I tried to add

tags$head(
    tags$style(HTML(
      ".navbar ul li:nth-child(4) { float: right; }
      .navbar ul li:nth-child(5) { float: right; }"
    ))),

but without desired effect.

like image 418
Adela Avatar asked Oct 01 '18 09:10

Adela


2 Answers

You could do that with some css. This would be an easy example which aligns the 4th and 5th list elements inside the class navbar-nav a float: right;.

By including right: 150px; to the 4th child, you keep the tabs in correct order.

App.R

library(shiny)   
library(shinythemes)  

ui =  tagList(
    tags$head(tags$style(HTML("
                           .navbar-nav {
                           float: none !important;
                           }
                           .navbar-nav > li:nth-child(4) {
                           float: right;
                           right: 150px;
                           }
                           .navbar-nav > li:nth-child(5) {
                           float: right;
                           }
                           "))),
  navbarPage(
    title = "My app",
    theme = shinytheme("cerulean"),
    navbarMenu("Left1",
               tabPanel("Subleft11"),
               tabPanel("Subleft12")),
    tabPanel("Left2"),
    tabPanel("Left3"),

    tabPanel("Right1"),
    tabPanel("Right2")

    )
    )

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

shinyApp(ui, server)
like image 98
SeGa Avatar answered Sep 26 '22 00:09

SeGa


Maybe something along these lines:

tags$head(
    tags$style(HTML(
    "
    .navbar-header { width: 10% }
    .navbar-nav { width: 90% }
    .navbar-nav>li:nth-child(4) { float: right; }
    .navbar-nav>li:nth-child(5) { float: right; }"
)))
like image 25
kluu Avatar answered Sep 27 '22 00:09

kluu