Creating a balanced layout for text of varying lengths in a fluidRow within an R Shiny application

As I work on developing a Shiny app, I am encountering an issue with displaying text blocks. These blocks vary in length, and my goal is to color each block while also creating some spacing between them.

The challenge I face is that due to the varying text lengths, coloring only extends up to the text itself, leaving empty spaces which results in a less-than-ideal appearance.

Additionally, the minimum gap between columns seems to be fixed at 1, which is visually too large for my liking.

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

My aim is to color Columns B & C up to the length of Column A, and at the same time reduce the gap between columns. Despite setting the offset to 1, I am unable to achieve a fraction less than 1.

Here is the current code resulting in the image above:

    ui <- fluidPage(
  mainPanel(
    tabsetPanel(
      tabPanel("Data Visualization",
               fluidRow(
                 column(3,h3("Title A",align = "center"),style = "background-color: red;"),
                 column(3,h3("Title B",align = "center"),style = "background-color: yellow;",offset = 1),
                 column(3,h3("Title C",align = "center"),style = "background-color: green;",offset = 1)
               ),
               fluidRow(
                 column(3, h4(tags$li("Text A")),style = "background-color: red;"),
                 column(3,tags$li(h4("Text B")),style = "background-color: yellow;",offset = 1),
                 column(3,tags$li(h4("Text C")),style = "background-color: green;",offset = 1)                       
               ),
               fluidRow(
                 column(3, h4(tags$li("More Text A")),style = "background-color: red;"),
                 column(3,"",style = "background-color: yellow;", offset = 1),
                 column(3,"",style = "background-color: green;", offset = 1)                       
               ),    
               fluidRow(
                 column(3, h4(tags$li("More and More Text A")),style = "background-color: red;"),
                 column(3,"",style = "background-color: yellow;", offset = 1),
                 column(3,"",style = "background-color: green;", offset = 1)                       
               )
))))

server <- function(input,output) {}

shinyApp(ui = ui, server = server)

I am seeking a solution to style this without relying on hardcoded pixel widths, as this could impact the user experience on different screen sizes and devices. Any advice on achieving equal coloring up to the length of the longest column or alternative methods for creating text boxes in Shiny would be greatly appreciated.

Thank you in advance for your assistance!

Answer №1

An alternative and more straightforward solution could be using the shinydashboard::box() function:

library(shiny)
library(shinydashboard)

dashboard_body <- dashboardBody(
  tags$head(tags$style(
    HTML('.row div {padding: 0% 1% 0% 1% !important;}'))),
  
  fluidRow(
    box(
      title = "Title A", width = 4, background = "red",
      "Some content inside a red box."
    ),
    box(
      title = "Title B", width = 4, background = "yellow",
      "Some longer text inside a yellow box."
    ),
    box(
      title = "Title C",width = 4, background = "green",
      "Some content inside a green box."
    )
  ), 
  
  fluidRow(
    box(
      width = 4, background = "red", 
      "Additional text for topic A."
    )
  )
)

ui <- dashboardPage(
  dashboardHeader(title = "Example of a Dashboard"),
  dashboardSidebar(),
  dashboard_body
)

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

This method provides the following layout: https://i.sstatic.net/OBgS9.png

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

Applying a live status to a particular component (Navbar)

Currently, I've been diving into creating a navbar and wrestling with some jQuery code that was passed my way. I'll be sharing my code below, along with a Codepen link (https://codepen.io/JustNayWillo/pen/aXpKbb) for a better understanding of th ...

Creating a custom variable assignment in Bootstrap within the custom.scss file

I've been searching for a solution to this problem for half a day now. My goal is to change the value of the $primary variable from the default $blue to the $orange variable. I tried following the instructions in the documentation: $primary: red; @imp ...

Having trouble updating the icon on my website using FontAwsome

Just a heads up - I'm not familiar with HTML/CSS/JS. This template is pre-made, and I'm simply making some adjustments to it. Hello, I'm currently working on my portfolio website and I want to display my projects based on the programming la ...

The background image doesn't extend to the bottom of the page due to the inability to utilize background-attachment

Currently, I am working on a project that requires a background image to cover the entire page. Unfortunately, using "background-attachment: cover" is not an option due to the need for compatibility with iOS, which does not support this property. .sky-b ...

Guide to adding content and icons to the top navbar on the right side using vue.js

In the process of developing a fixed top navbar, I encountered an issue while trying to add right side icons and additional content. The goal is to include two icons, as shown in this example: example link, along with profile and cart information on the ri ...

Arrange the two buttons in a vertical position

Excuse any weak code you may come across, as I am a backend developer. This is the current appearance of my form: The alignment of these two buttons in Chrome is not correct The issue only occurs in Chrome, with FireFox and Edge displaying the form as e ...

Leveraging Template Variables for Styling in Vue 3's CSS Classes

Struggling to find the perfect way to utilize variables returned by Vue functions in CSS inline styles, specifically with the "width" style. I have two variables that are returned to the template and can be used with the {{}} syntax, but not directly as a ...

"Enhancing Website Styling with Twitter Bootstrap's Border

Recently delving into the realm of Twitter Bootstrap, I find myself pondering on the best approach to incorporate a border around a parent element. Consider this scenario: <div class="main-area span12"> <div class="row"> <div cl ...

The twelfth child in the sequence is not functioning properly, although the others are working correctly

In my list, I have 12 elements and each element contains a div. My goal is to set different sizes for each div by using nth-child on the li element. However, the configuration for the 12th element does not seem to work correctly compared to the rest of the ...

I'm trying to create a horizontal list using ng-repeat but something isn't quite right. Can anyone help me figure out

Feeling a bit lost after staring at this code for what seems like an eternity. I'm trying to create a horizontal list of 2 image thumbnails within a modal using Angular's ng-repeat. Here's the HTML snippet: <div class="modal-body"> ...

Tips for organizing a grid to achieve the desired layout

Overview I am working on organizing items within the MUI Grid. The grid consists of multiple dynamic rows and columns. Each row has a fixed first column, followed by a variable number of scrollable columns. The scrollable columns should be grouped togethe ...

Changing the height of a pseudo element according to the width of the viewport in a dynamic way

Currently, I am utilizing the :before pseudo-element on a 100% width div to create a curved top, which is functioning correctly. However, I am facing the issue of adjusting the height of the :before element through media queries whenever the browser width ...

What are the recommended web-safe colors to use for styling an <hr> element?

Having an <hr> element with the color #ac8900 is what I require. When I apply the style in the traditional way <hr color="#ac8900"> it functions perfectly. However, the expectation is to style everything using CSS, so I attempted the followin ...

Revamp the Bootstrap Carousel Control by replacing the default navigation arrows with stylish arrows featuring circle backgrounds

Looking to update the appearance of the carousel icons in Bootstrap 4? How about changing them from simple arrows to arrows with dark semi-opaque circles underneath? If you're wondering how to achieve this modification, keep in mind that the icons ar ...

Adjust Element Width Based on Scroll Position

I'm attempting to achieve a similar effect as seen here: (if it doesn't work in Chrome, try using IE). This is the progress I've made so far: http://jsfiddle.net/yuvalsab/op9sg2L2/ HTML <div class="transition_wrapper"> <div ...

Tips for showcasing the chosen menu item in the toggle button of the Bootstrap framework

I have created a collapsible menu that is hidden when the browser is resized and should be displayed when the button is toggled. Currently, I am using glyphicon-humberger in the toggle button. However, I would like to show the selected menu in the button ...

PHP: Bootstrap CSS for Carousels

I'm experiencing some difficulties with the Bootstrap CSS Carousel on my website. The left and right arrows seem to be unresponsive, and the slides are not transitioning automatically. I have been unable to identify the root cause of this issue. Belo ...

Error: The system was unable to locate the object in the specified

Here is a function I created to output the summary of an ANCOVA and visualize the results: analyzeAncova <- function (data, response, covariate, grouping) { library(ggplot2) model <- aov(response ~ covariate + grouping, data=data) prediction ...

Can anyone suggest a more efficient approach to handling variations using CSS?

Within the message component, there are currently only two variants available: error and success. This project is built using vue3 script setup and utilizes SCSS for styling. <script setup lang="ts"> defineOptions({ name: 'Notificat ...