Adjusting the sidebarPanel height to match the mainPanel content in a shiny app

I'm currently developing an app that features a scrollable sidebarPanel alongside a mainPanel that can have varying heights, such as:

library(shiny)

ui <- fluidPage(
  headerPanel('Iris k-means clustering'),
  sidebarPanel(style = "overflow-y:scroll; max-height: 600px; position:relative;",
               numericInput('clusters', 'Cluster count', 3, min = 1, max = 9),
               selectInput('xcol', 'X Variable', names(iris)),
               selectInput('xcol', 'X Variable', names(iris)),
               selectInput('xcol', 'X Variable', names(iris)),
               selectInput('xcol', 'X Variable', names(iris)),
               selectInput('xcol', 'X Variable', names(iris)),
               selectInput('xcol', 'X Variable', names(iris)),
               selectInput('xcol', 'X Variable', names(iris)),
               selectInput('xcol', 'X Variable', names(iris)),
               selectInput('xcol', 'X Variable', names(iris)),
               selectInput('xcol', 'X Variable', names(iris)),
               selectInput('ycol', 'Y Variable', names(iris),
                           selected = names(iris)[[2]])
              
  ),
  mainPanel(
    plotOutput('plot1'),
    conditionalPanel("input.clusters == 2", 
                     plotOutput('plot2') 
    )
  )
)

server <- function(input, output) {
  output$plot1 <- renderPlot({
    plot(x=iris$Sepal.Length, iris$Sepal.Width,
         col = iris$Species, pch = 20, cex = 3)
  })
  
  output$plot2 <- renderPlot({
    plot(x=iris$Petal.Length, iris$Petal.Width,
         col = iris$Species, pch = 20, cex = 3)
  })
  
}

shinyApp(ui = ui, server = server)

As the height of the mainPanel changes when cluster equals 2, I am wondering if there is a way to make the height of the sidebar automatically adjust to match the mainPanel output. This would ensure that the sidebar always reaches the bottom of the page while still being scrollable.

I suspect it has something to do with the max-height css parameter, but I'm unsure how to proceed from here.

Any suggestions would be greatly appreciated!

Answer №1

It seems like the issue is related to the max-height parameter. One way to define this parameter is by using relative units. I came up with these two solutions:

  • resizing a div based on window width
  • Understanding CSS Units - vh/vw vs %

To set the height, you can use max-height: 100% for a height of 100% relative to the parent div element, or max-height: 100vh for 100% relative to the viewport height (browser window). You can also choose different values instead of 100.

In my experience, a value like 90vh tends to work well in most cases.

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

Shrink or vanish: Creating a responsive header image with Bootstrap

Looking to create a dynamic header with different sections such as headerright, headercenter, and headerleft, each with unique content. I've successfully added an image to the header, but when I resize the page or view it on a mobile browser, the ima ...

BOOTSTRAP: changing the layout of panels in various sizes for mobile devices

I'm struggling with how to reorganize my panels on mobile devices. Each panel has a different size. Please refer to the attached screenshot for the page layout on large screens (col-lg): https://i.sstatic.net/xcqaT.png EDIT: The layout on large scre ...

Align Text Center inside a Magical H1 Heading Tag

I'm having a bit of trouble with something that should be simple. I want to center the text inside my h1 tag on a wizard, and I've added this CSS to my stylesheet.css: .h1textalign { text-align:center; } Here's how I'm trying to apply ...

Removing a faded out div with Vanilla JavaScript

I am struggling with a JS transition issue. My goal is to have the div automatically removed once it reaches opacity 0. However, currently I need to move my mouse out of the div area for it to be removed. This is because of a mouseleave event listener that ...

The Bootstrap grid is not aligning to the center when dynamically adjusting sizes

I am currently in the process of developing a store website using bootstrap. One issue I am facing involves creating a grid for my product display. The problem is that the number of grid cells remains constant even when the screen size is reduced. I would ...

display the information stored within the sports attribute using React

I am attempting to display the values stored in the sports property. So, I inserted a console log within the sports property. However, an error is being thrown: Syntax error: C:/codebase/src/containers/sports.js: Unexpected token, expec ...

The problem of border-radius bleeding in Webkit when applying -webkit-transform

After creating a basic jQuery script to slowly rotate an image, I encountered an issue where the rotated image would bleed over the border-radius in Chrome. The rotation works smoothly in Firefox 4.0.1 but not in Chrome. To see the example and code, check ...

span element causing border-spacing problem

Is there a way to adjust the spacing between these borders? I've tried using border-spacing but it doesn't seem to be working. {{#each spacing}} <span class='space'> {{business}} ({{Count}}) </span> {{/each}} CSS .spac ...

Conceal the browser scrollbars

When I have two DIVs on my webpage that are larger than a browser window, it results in a horizontal scrollbar being displayed. How can I hide this browser scrollbar for the first DIV while still showing it for the second one? For example, if I have two ...

Enhanced Fancybox Version 2 adjusts iframe width to fit content

I have been attempting to adjust the width of the iframe in fancybox v2 to fit my content properly. However, every time I try, the content appears too large within the iframe and requires horizontal scrolling to view it all. My goal is to see the entire wi ...

Move the components over to the right

How can I vertically align the user and the search bar on the right side of the page? #search { float: right; margin-top: 9px; width: 250px; } .search { width: 230px; height: 30px; position: relative; line-height: 22px; } ...

Locate the local minima and maxima within the data set and utilize this specific range for generating the

Hey there, I've got some data here. Feel free to copy and paste it into a text file as CSV because exporting it as vectors seemed tricky :) Now, when plotted on a scatterplot, you'll see a clear maximum point. What's the best way to create ...

Alignment issue with Bootstrap 4 form fields within inline form group

My experience with Bootstrap 4 on certain pages has been quite challenging, specifically when it comes to aligning fields with labels to the left and maintaining an aligned appearance for input fields. Here is the snippet of my code: <div class="wrap ...

Transform JavaScript variables into CSS variables

Similar Post: Avoiding repeated constants in CSS I am currently working on a javascript file that aims to adjust my site's resolution based on the width and height of the viewport. While I have successfully retrieved these values using JavaScript ...

Text "movement/vibration" in screen when adjusting dimensions in Firefox for Mac

I am currently involved in a project centered around showcasing a variety of fonts to users for them to experiment with, allowing them to adjust size and spacing using sliders. While the functionality works seamlessly on Chrome and Safari, a peculiar issu ...

Aligning a div within another div and organizing its elements

Hey everyone, I'm struggling with centering a div that contains two Tumblr posts columns, as shown in the screenshot linked below. I really want it to be centered on the page where there is no sidebar present. Additionally, I'm hoping to get the ...

The transparency of my navbar renders it elegant, yet I desire to imbue the toggle background with a vibrant hue

I'm facing an issue with the transparent Navbar I built in Bootstrap 5. On mobile toggle view, the navigation links are getting lost within the text of the hero image. To resolve this, I want to keep the main navigation bar transparent and change the ...

Instructions on integrating a column of buttons into a Bootstrap table containing information retrieved from a MySQL database

My bootstrap table is currently displaying data that is loaded from a MySQL database. I am looking to enhance it by adding a column with buttons, similar to the layout shown in this image. https://i.stack.imgur.com/8fWfR.png However, I am facing some dif ...

Angular Markdown Styling: A Guide

Currently, I am using Angular and Scully. I would like to add style to the image in a markdown file within Angular, but I am unsure of how to accomplish this task. The image is currently displaying too large. Can anyone provide me with useful advice on how ...

Is there a way to adjust the time font size according to the dimensions of the time picker?

HTML and CSS .pickthetime { height: calc(var(--vh, 1vh) * 3); width: calc(var(--vw, 1vw) * 25); align-content: center; // center looks better, also tried left to stop it from breaking a new line on Safari on iOS font-weight: 300; } <input cla ...