Creating a Gap in R Shiny Interface Between Two Data Tables

I am currently working with R and Shiny, and I am attempting to display two dataTableOutput elements next to each other. To accomplish this, I am utilizing the fluidRow column feature, but I need to further customize the width of these two tables. Here is the code:

# The following code reduces the size of the pagination buttons
tags$style(HTML("".dataTables_wrapper_aa .dataTables_paginate .paginate_button {
                                         min-width: 0.5em !important; 
                                         padding: 0.1em .5em !important;
                                         } 
                                         ")),
                         
                         # 
                         tags$style(HTML("".pagination_aa {
                                                          display: inline-block !important;
                                                          }
                                            
                                            .pagination_aa a {
                                            color: black !important;
                                            float: left !important;
                                            padding: 8px 16px !important;
                                            text-decoration: none !important;
                                            font-size: 12px !important;
                                            }
                                         ")),

                         # This code segment should customizes and makes the two tables extremely tight (it's a test), but in reality, it doesn't have any effect. Why?
                         tags$style(HTML("".optim_mp_table02 .table>tbody>tr>td, .table>tbody>tr>th, .table>tfoot>tr>td, .table>tfoot>tr>th, .table>thead>tr>td, .table>thead>tr>th {
                                                    border-collapse: collapse;
                                                    width: 10px !important;
                                         }
                                         "))

Then, here is how I use the tags mentioned above:

fluidRow(column(width = 3,
                                       offset = 0, # this seems useless
                                       style='padding:10px;', # this seems useless
                                       tags$div(class="dataTables_wrapper_aa pagination_aa", 
                                       DT::dataTableOutput(outputId="table01angelo", 
                                       width = '10px' # this seems useless
))),
                                    column(width  = 3
                                           #,offset = 0
                                           #,style='padding:10px;',
                                           ,tags$div(class="dataTables_wrapper_aa pagination_aa optim_mp_table02", 
                                                    DT::dataTableOutput(outputId="table02angelo", width = '10px')))
                                    ))

I have tried numerous combinations (keeping in mind that I am new to html/css) and also referred to the following two questions shiny fluidrow column white space and Controlling table width in Shiny dataTableOutput, but I still end up with two tables overlapping each other! On the other hand, I could resolve this issue by using column width = 4, but that would take up too much space. Since there are a total of 12 columns available, I ultimately need to have 4 tables, each taking up 3 columns. I have also attached a screenshot. Thank you for the assistance. https://i.sstatic.net/z5fTb.png

One more thing, in case it might be helpful. Both tables are created in the following way:

output$table01angelo <- DT::renderDataTable({  
  df <- get_mp_data()
  if(is.null(df)){
    df <- data.frame()
  }else{
    upcolor = "lightblue";
    downcolor = "lightblue";
    col_name = "CHG";
    df <- datatable(df
                    , rownames = FALSE 
                    , caption = paste0("Pre/Post Duration")
                    , filter = 'none'
                    , options = list(scrollX = F
                                     #, lengthChange = FALSE  # this feature hides the "Show Entries" on top of the table, so we won't be able to customize how many entries we can see all together
                                     , language = list(lengthMenu = "_MENU_") # this feature hides the text "Show Entries" but does keep the dropdown box to change the # rows per page
                                     , pagingType = "numbers"  # this hides the Next and Previous buttons -->  https://datatables.net/reference/option/pagingType
                                     , autoWidth = T
                                     , pageLength = 5 # this determines how many rows we want to see per page
                                     , info = FALSE #  this will hide the "Showing 1 of 2..." at the bottom of the table -->  https://stackoverflow.com/questions/51730816/remove-showing-1-to-n-of-n-entries-shiny-dt
                                     , searching = FALSE  # this removes the search box  -->  https://stackoverflow.com/questions/35624413/remove-search-option-but-leave-search-columns-option
                                     , columnDefs = list(list(width = '4', targets = c(3) ) 
                                                        , list(width = '4', targets = c(2) )
                                     )   # careful, column counting STARTS FROM 0 !
                    )) %>% 
      formatStyle(col_name,
                  background = color_from_middle(df[, c(col_name)], downcolor, upcolor),
                  backgroundSize = '98% 88%',
                  backgroundRepeat = 'no-repeat',
                  backgroundPosition = 'center')
  }
  return(df)
})

Answer №1

It appears that your code is functioning properly when using the standard dataframe mtcars. Take a look at the results when only selecting 4 variables from mtcars:

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

However, when opting for 6 variables, the output is as follows:

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

In this case, the 6th column of table 1 is positioned behind the first column of table 2. Since you want each table to take up 25% of the page width, displaying too many columns won't work as autoWidth=T assigns a set width to each column.

You might want to refer to @Stephane Laurent's response here, and place css above ui and columnDefs with nowrap.

Alternatively, as proposed by @DanWaters, enabling scrolling will lead to the following output:

https://i.sstatic.net/Rj3fL.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

What is the best way to incorporate a button in my code that automatically triggers changes at regular intervals?

Is there a way to automatically change the color of my working traffic light in JavaScript on a timed basis, rather than relying solely on button clicks? Here is the current code I am using: <!DOCTYPE html> <html> <head> <style> # ...

Create an HTML div element that spans the full width of the

I'm facing an issue on my HTML page where a div containing users from a chat system database is not displaying correctly. The ul li tag within the parent div is not taking up the full width as expected. Here's how it should look: http://prntscr.c ...

Extract the entire div including all its elements and then transmit it using the PHP mail function

Currently, I am developing a feature that allows users to send an email. The email should include only one div from the page which contains elements added using the jQuery drag and clone function. I am unsure how to copy the entire div along with its child ...

What is the best way to eliminate empty spaces from the container?

click here check out this image too Just getting the hang of Bootstrap. The first picture looks good, with the image as the background. But on the second picture, there are margins and a background color showing up. How can I get rid of those margins? Her ...

Iconic Navigation: Bootstrap 3 Navbar featuring Carousel

I'm currently in the process of developing a website using bootstrap3. Despite watching numerous tutorial videos, I am still facing challenges. One of my goals is to have the logo on the navbar aligning with the left side (which I've achieved ...

I am seeking assistance with developing a customized sorting algorithm for a DataTable in VB.NET

I am working with a datatable that contains multiple columns, but the three main ones are: hotelid dshotelid hotelname Some hotels have only dshotelid, some have only hotelid, and some have both dshotelid and hotelid. I am trying to sort the datatable ...

Positioning a div with text over an image in a way that it

Hey everyone, I've run into a bit of an issue with my project. I'm trying to create a system where text appears over an image, but the problem is that my div is set to absolute position and I can't switch it to relative without causing major ...

What is the best method for creating a vertical line separator with a hover effect in CSS?

Facing an issue with creating a vertical line separator in the navigation menu. While trying to add a vertical line separator to my navigation, I noticed that it does not get covered by the hover effect when hovering over the menu items. Please refer to t ...

My form does not receive the Bootstrap classes when using the jQuery script

**Why isn't my jQuery script coloring the rows as expected when certain conditions are met (I italicized the specific part of the code)?** Here is the HTML CODE for the POLL: <form id="pollForm" class="mb-4"> <d ...

Arrange the buttons within the container

I'm struggling with the front-end development side of things (HTML, CSS, etc.) and need help aligning buttons within a container. The container will include a heading and multiple buttons. Any assistance would be greatly appreciated! Thank you in adv ...

Experiencing an issue while rendering due to the presence of display: table-cell;

I am currently in the process of developing a website. The HTML Header section is structured as follows: <div id="page"> <header> <a href="#" class="redsquare">&nbsp;</a> <div class="head-wrapper"> ...

Exploring the contrast in importing CSS between the HTML header, JS file, and Vue Component

Exploring the world of Vue with webpack, I find myself curious about the various ways to import CSS. It appears that there are three methods for importing CSS: Adding style sheets directly to HTML headers: <link type="text/css" rel="stylesheet" ... &g ...

Unknown CSS element discovered: bootstrap, gradient, carousel

I recently created a random quote app using javascript, jQuery, and bootstrap on Codepen. Everything worked perfectly there. However, when I organized the files, pushed them to git, and tried to view the app from Safari, I encountered some warnings and t ...

Using R (dplyr) to incorporate the "minimum" requirement into a filter

This post is in reference to a question I previously asked on Stack Overflow: Consecutive exceedance above a threshold and additional conditions in R Below is the dataset: dat <- structure(list(V1 = c(-3.85326, -2.88262, -4.1405, -3.95193, -6.68925, ...

Loop through each div using jQuery and dynamically add or remove a class to

I am looking to create an infinite loop that adds a class to each div with a timeout in between. Currently, I have implemented it like this: $(document).ready(function() { $('.small-bordered-box').each(function(i) { var $t = $(this); ...

Accordion nested within another accordion

I am facing a challenge while trying to nest an accordion within another accordion. The issue is that the nested accordion only expands as much as the first accordion, requiring additional space to display its content properly. Any assistance with resolvin ...

What are the best ways to ensure that my side menu, bottom buttons, and content are all responsive

I have been struggling with creating a responsive side menu in my HTML code. Despite my efforts, the side menu contents, buttons, and layout do not adjust properly when resizing the browser window. When I drag the browser size from bottom to top, the butto ...

Create a scrollable Bootstrap table without impacting the layout grid system

Is there a way to create a scrollable table without impacting the grid system layout? How do I make a table scrollable while keeping the col-xs tag intact? <table class="col-xs-12"> <thead> <th class="c ...

Eliminate missing values from geospatial dataset

Struggling to remove NAs from a "SpatialPolygonsDataFrame". Traditional data frame approaches and subsetting methods have proven ineffective in this case. Even attempts to eliminate NAs as one would for a regular data frame have failed. The solutions that ...

Achieving Equal Heights for Nested DIVs within Containers

Below is the snippet of code I need help with: <table cellpadding="0" cellspacing="0" style="background-color:Aqua"> <tr> <td> <div style="background-color:Yellow">Navigation</div> </td> ...