Donny Lee
Donny Lee

Reputation: 13

Shiny - how to center and fix width of dashboard

Hello R Studio Community,

I've been developing an app in Shiny and it's be great. I have one simple question.

As different browsers have different widths, is there a way to set the rule on resizing the Shiny dashboard based on the following:

1) If browser width is more than x, limit to width to x and center the entire dashboard

2) If browser width is less than x, follow default autosizing

3) Not essential. But how do I set the blank space color to the left and right of the dashboard

Fix width shiny dashboard

The motivation is that I need a fixed width so that some pictures are scaled correctly. I hope my request can be done through some div tag on the dashboardPage.

This is the current behavior which I do NOT want.

Shiny dashboard stretches to fit window

Cheers, Donny

Upvotes: 1

Views: 1880

Answers (1)

Bertil Baron
Bertil Baron

Reputation: 5003

Hi to achive what you are asking for just add the following code to the beginning of your dashboardBody. something like this

dashboardBody(

    tags$head(
      tags$style(
        "body{
    min-height: 611px;
    height: auto;
    max-width: 800px;
    margin: auto;
        }"
      )
    ),
   ... #the rest of you ui code

hope this helps

Upvotes: 4

Related Questions