Sparkling bslib() and Interactive Tables nestled within a Stylish Bootstrap Card

I really appreciate the way design elements are placed inside a card, similar to the example I found on the blslib() website. However, when I try to implement it on my screen, it doesn't appear the way I expected. Instead of seeing 10 rows displayed, I only see two rows with a scroll bar. I assumed that using the fillContainer argument would automatically adjust the table to fit within the card space.

Does anyone have a solution to make the table fill the card with the specified number of rows set by the page length option?

bs4_card <- function(body, title) {
  div(class="table-responsive",
    class = "card",
    div(class = "card-header bg-primary", title),
    div(class = "card-body d-flex justify-content-center", body)
  )
}

shinyApp(
  fluidPage(
    theme = bslib::bs_theme(primary = "orange"),
    uiOutput("dat")
  ),
  function(input, output) {
    output$dat <- renderUI({
      table <- DT::datatable(mtcars, fillContainer = TRUE, style = "bootstrap4", rownames = FALSE)
      bs4_card(table, "The mtcars dataset")
    })
  }
)

EDIT: I discovered that including

class="table-responsive"
as mentioned in my previous edit, changes the table rows based on pagination. Modifying the pagination settings also affects the display with a scrollbar added accordingly.

I personally prefer the card size to adapt according to the table's rows rather than having a scroll bar present.

It seems like there may be a specific CSS class for this, but my knowledge is limited in that area.

Answer №1

If you want the card size to match the table size, simply include height = "100%" in your DT::datatable() function like so:

DT::datatable(mtcars, style = "bootstrap4", rownames = FALSE, height = "100%")

Remember to delete fillContainer = TRUE.

Answer №2

Apologies for the delayed response, but I'm not certain if this solution will resolve your issue.

If you're working with DataTables within Bootstrap tabs and need to readjust the layout after making changes, there is a handy function available.

Check out this link for more information on columns.adjust()

var table = $('#example').DataTable();

$('#container').css( 'display', 'block' );
table.columns.adjust().draw();

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

Looking for assistance with floating CSS header elements

While working on my web design project, I encountered an issue when trying to align the [LEFT LOGO], [TITLE (CENTER)], and [RIGHT LOGO] elements. The problem occurred with the RIGHT LOGO, as it was not aligning properly with the LEFT LOGO. Instead, the ri ...

Mobile browsers are not displaying placeholder transparency in CSS as expected

I'm trying to create input fields with fully opaque placeholder text <input type="text" placeholder="Enter your name here" /> Even though I've applied CSS properties to fix the transparency in Firefox, the text still appears translucent ...

JavaScript functions do not work within the HTML code

I am currently working on my debut website and I'm facing an issue with the JavaScript file not functioning properly. Is there a chance you can help me troubleshoot this? I'm still in the learning stages of programming. This is the HTML content ...

Utilize CSS to create spacing between columns in a webpage

I have incorporated a table into my project and here is the HTML snippet for reference: th { text-align: left; } td { height: 20px; font-size: 12px; background-color: #000; color: #fff; margin-right: 20px; border-top-left-radius: 10px; } ...

What is the best way to implement overflow hidden in an unordered list?

My goal is to achieve the following: - - I am struggling with keeping my unordered list on a single line with overflow:hidden. I want the ul to flow naturally without restructuring the HTML or using absolute positioning for the arrows. Can you help me w ...

"Browser failing to display HTML elements within <div> tag

https://i.sstatic.net/i1hMC.png I'm struggling to find a solution for properly rendering HTML elements within the div. Do you have any suggestions? The content is retrieved from a database and then inserted into the div through Handlebars. ...

Develop a custom WordPress meta box for managing the color scheme of individual posts and pages

Currently, I am in the process of learning how to create a custom WordPress meta box with a select tag for controlling the color scheme of individual posts/pages. My goal is to implement a system where I can use if statements to load an additional CSS file ...

Creating a bezel design in CSS or Vue: A step-by-step guide

Embedding: https://i.sstatic.net/YfvQP.png Is there a CSS property that can be used to create the same angle as shown in the layout? I looked everywhere in the program but couldn't find this specific property. Tried searching here !: https://i.s ...

What are the steps to generate and visualize the frequency class intervals of a numerical column in a dataset?

I am working with a column of numbers representing drug dosages in a data frame. The numbers range from 0.023 to 122 and do not follow a specific pattern - the minimum and maximum values are 0.023 and 122. How can I divide these numbers into intervals an ...

Steps for changing the background color string in mui?

I have a component where I am trying to dynamically change the color based on the user type. The issue arises when I use gradient colors, as the transition stops working. If I stick to simple colors like blue, red, or green, it works fine. Currently, the c ...

Having an issue with the 'scroll' event not being disabled in jQuery

Currently, we are encountering an issue with the implementation of a simple hiding menu when scrolling and showing it back once the user stops scrolling. The method .on('scroll') works as expected, but .off('scroll') is not functioning ...

An artistic arrangement of images seamlessly fitting together in a rectangular shape using HTML and CSS

I am currently working on creating a collage of images that need to fit perfectly within a rectangle. I have successfully completed the top layer, but I am facing some confusion with arranging the images in the last row using CSS. (For better visualization ...

Visualization of data points on a transformed dataset using scatter plot

Let's say we have some data stored in a dataframe called dt, where the columns are id1, id2, and value. We want to create a scatter plot of values from id1 vs id2. One way to do this is by reshaping the data using the ggplot2 and tidyr libraries: lib ...

The dropdown menu functions smoothly in Firefox, although it may be less consistent in Chrome

I am encountering an issue with my JavaScript drop down menu. It functions properly in Firefox (version 57), but in Chrome (version 62) the drop-down only appears after clicking elsewhere on the page before clicking on the menu icon or button. My code in ...

What is the best way to apply hover effects to all links except the one being hovered over, using a combination of javascript, jquery,

While browsing the web, I came across a fascinating hover effect that I'm eager to replicate in a website's navigation bar. This effect doesn't just change the link you hover over, but it alters every other link in a unique way. When hoverin ...

adjusting the length of the right boundary

I am looking to customize the size of the right border on each tab within my menu, or have the borders extend the entire vertical length of the menu. View my current code snippet here: http://jsfiddle.net/5FP8R/ <div id="menu"> <ul> ...

How can I style my text using CSS with a linear gradient, shadow, and outline effect

Can text be styled with a linear gradient, shadow, and outline all at once? I'm running into an issue where setting "-webkit-text-fill-color: transparent" for the gradient causes the shadow to appear on top of the text. Is there a way to have the te ...

Angular Material Spinner with Custom Image Icons - (mat-spinner)

I have successfully implemented the mat-spinner in my project with configurable changes like color and mode of spinning. However, I am now looking to add an image icon, specifically the logo of a brand or company, inside the spinner. How can I achieve this ...

Place a full-width block within a grid design

I am currently working on a page layout inspired by Google Images. It features a grid of images with a large full-width section underneath the selected image. I am interested to see if it is achievable using CSS properties like display: grid. https://i.ss ...

Styling the center menu

Is there a way to horizontally center this top menu using CSS? https://i.sstatic.net/9yvJf.png This is the HTML structure I am working with: <div class="wrapper_menu_hoz"> <div class="container_24 "> <div class="gr ...