Several tabPanels aligned to the right in shiny

Is there a way to align certain tabPanels to the right and others to the left within a navbarPage in Shiny?

For example, instead of the default alignment like 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)

I am looking for an output similar to this:

https://i.sstatic.net/wTJFG.png

Although I found a solution on Stack Overflow by user GyD for tabsetPanel, I have been unable to apply it to navbarPage. I attempted to add the following CSS code:

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

However, it did not produce the desired result.

Answer №1

Styling with CSS can help achieve the desired layout. Here's a simple example that adjusts the positioning of the 4th and 5th list elements within the navbar-nav class using float: right;.

To ensure the tabs display correctly, add right: 150px; to the 4th child element.

Custom Styling in 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)

Answer №2

Here is a possible solution to the problem:

tags$head(
    tags$style(HTML(
    "
    .menu-header { width: 15% }
    .menu-items { width: 85% }
    .menu-items>li:nth-child(3) { float: right; }
    .menu-items>li:nth-child(4) { float: right; }"
)))

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Struggling with converting my menu design into a dropdown menu

Recently completed creating my initial menu with a left navigation bar design. Wondering if it is achievable to implement a dropdown effect on hover without the use of javascript? I have come across several solutions but they do not seem to work for me, po ...

What is the best way to create exclusive toggle buttons using jQuery?

I am currently working on a project where I need to create functionality for three buttons, each triggering a unique graph effect. The key requirement is that when one button is pressed, the other two should be deactivated along with their corresponding fu ...

Creating a circular price display using CSS:

Below is the code snippet that I am working with: .special-price { text-align: center; background-color: #2e566e; } .special-price .offer { border-radius: 50%; background-color: #56c243; color: #fff; font-weight: 700; font-size: 18px; h ...

Attempting to create a login and registration form

Hello, I am attempting to create a form that can generate new user accounts and passwords. These values should be stored from the input tag when the user clicks on the register button. Unfortunately, I am encountering an issue where clicking the register ...

Guide on altering the background color of dynamically generated textboxes in R Shiny

textInput(paste0("inp1-", wid),label = NULL,value = record$Current_week) This code was used to dynamically generate text input boxes, where the id for each box is determined by a number called wid. I attempted to change the background color using the fol ...

Show the page links on the custom WordPress theme's home page

This is my first time creating a wordpress theme from scratch and I could use some assistance with tackling two specific challenges involving the WP_Query class and the navigation menu. My goal is to showcase the titles and featured images of pages on the ...

What is the best way to display rows in alternating red and green colors?

Currently, I am implementing the react table in my React project. I found valuable resources on how to use it at these links: https://github.com/tannerlinsley/react-table/tree/v6#codesandbox-examples and also here: https://www.npmjs.com/package/react-tab ...

Navigating the carousel doesn't have to be complicated using Onsen-UI, especially when you want to

Currently, I am utilizing Onsen-ui along with angularjs. My issue lies in attempting to center images within a carousel, as they consistently align to the left. Below is the code snippet that I am working with: <ons-carousel direction="horizontal" styl ...

Conceal an element within the initial row of the table

Below is the table structure: <table id="mytable"> <tr> <td>name</td> <td> <a id="button1" class="button">link</a> </td> </tr> <tr> <td>name2</td> ...

Extracting the text on the left side of the parentheses in R: A comprehensive guide

I need to extract specific text from a given string String=“Text1.Text2(er2019).Text3(246)text.” The desired output should be: String=“Text2.Text3” I am looking to only get Text2 and Text3, the part before the parentheses in the 2nd and 3rd ele ...

Apply a rolling linear model to calculate and save the predicted values

I am working with time series data and would like to perform "mini" regression models on it in a rolling fashion. The following code snippet demonstrates how I can run a linear model and plot it: mod <- lm(Y1 ~ time(data), data = data) ggplot(data, ae ...

aggregate data from various columns based on groups

Is there a way to sum multiple columns by group in a more efficient manner? Consider the following dataset where the expected result can be achieved using base R split-apply functions: library(data.table) set.seed(1234) df1 = data.table(grp = sample(0:2, ...

Exploring correlation patterns across matrix columns using loops in R

I am working with a 200x200 matrix of simulated models and aim to calculate the correlation between specific columns. Shared below is a snippet of the data: var1 var2 var3 var4 [1,] 0.000000000 0.0000000000 0.00000000 0 ...

Ways to prioritize the parent element's style over the child element's style attribute

I am looking to customize the appearance of an unfamiliar HTML code by changing its text color to cyan, regardless of its current color. I attempted the following: <p style="color:cyan !important;"> <span style="color:red;">Hello World</ ...

What could be causing only certain portions of my CSS to be applied?

I've been struggling to get rid of the gray border around the SIGN UP button in the tbody section. I've tried applying classes (along with the ID) and using pseudo classes like :4th-child {border:none}, but nothing seems to work. The only solutio ...

Guide on aligning a button in the middle of a form with bootstrap 4

In the form below, I have a button that is currently aligned to the left: <form> <div class="form-group"> <button type="submit" id="getmyestimate" disabled class="standard"gt; ...

Is it possible to insert uneditable text in a form field using only CSS?

I'm attempting to create a form input field with a specific format. The field should appear as: The prefix domain.com/username/ should be displayed as non-editable text (and not be submitted as form data), allowing the user to input their desired tex ...

When the training data is centered, XGBoost and Random Forest models consistently provide accurate predictions on the test set

Currently, I am engaged in analyzing omics data. My dataset has dimensions of 269x600, which I have divided into training and test sets in an 80-20 ratio. The variable I am looking to predict is the concentration of hippurate, which can take on four differ ...

Is it possible for JavaScript to capture scroll events while allowing clicks to pass through?

Currently, I have a setup where the user needs to interact with the layer behind the transparent scroll capture: http://jsbin.com/huxasup/4/edit?html,css,js,console,output scrollerCapture = document.querySelector('.scroller-capture'); scrollerC ...

@media query not functioning properly with certain rules

I've hit a roadblock because my @media query is functioning properly for the initial rule, but fails to work for subsequent rules. For instance, I managed to make the "subButton" disappear when the screen size decreases below the specified width. How ...