sizing shiny elements

16,005 views
Skip to first unread message

Vincent

unread,
Jan 30, 2013, 5:39:43 AM1/30/13
to shiny-...@googlegroups.com
If you put the following just below 'sidebarPanel' in ui.R various elements in your shiny app will be resized. I you have other/better ways to make adjustments please share.     

    tags$head(
        tags$style(type="text/css", "label.radio { display: inline-block; }", ".radio input[type=\"radio\"] { float: none; }"),
        tags$style(type="text/css", "select { max-width: 200px; }"),
        tags$style(type="text/css", "textarea { max-width: 185px; }"),
        tags$style(type="text/css", ".jslider { max-width: 200px; }"),
        tags$style(type='text/css', ".well { max-width: 310px; }"),
        tags$style(type='text/css', ".span4 { max-width: 310px; }")
      ),

Ksenia Titorenko

unread,
Feb 15, 2013, 1:42:56 PM2/15/13
to shiny-...@googlegroups.com
Hi, i tried to use your method for my ui.R
library(shiny)


# Define UI for application that plots random distributions 
shinyUI(pageWithSidebar(

  
  # Application title
  headerPanel("Clustering results"),
  
  # Sidebar with a slider input for number of observations
  sidebarPanel(
    helpText("There are 615 experiments\n",
             "and 230595 peptides.",
             "minExp = 2, minPep = 2."),
   
    selectInput("k","Method for choosing k for SVD:", 
                choices = c("Akaike information criteria (k = )", "Amended description length (k = )", 
                            "Percentange of var. explained = 0.5 (k = )","Percentange of var. explained = 0.8 (k = )",
                            "Percentange of var. explained = 0.95 (k = )")
    )
  ),
  tags$head(
    tags$style(type="text/css", "label.radio { display: inline-block; }", ".radio input[type=\"radio\"] { float: none; }"),
    tags$style(type="text/css", "select { max-width: 200px; }"),
    tags$style(type="text/css", "textarea { max-width: 185px; }"),
    tags$style(type="text/css", ".jslider { max-width: 200px; }"),
    tags$style(type='text/css', ".well { max-width: 310px; }"),
    tags$style(type='text/css', ".span4 { max-width: 310px; }")
  ),
  
  
  # Show a plot of the generated distribution
  mainPanel(
    tabsetPanel(
      tabPanel("Heatmap", plotOutput("heatmap",width = "800px", height = "800px")), 
      
      
      #tabPanel("Heatmap", plotOutput("heatmap",width = "1000px", height = "900px")), 
      tabPanel("Summary", verbatimTextOutput("summary"))
    )
  )
  
))
but it doesn't work:
Error in pageWithSidebar(headerPanel("Clustering results"), sidebarPanel(helpText("There are 615 experiments\n",  : 
  unused argument (mainPanel(tabsetPanel(tabPanel("Heatmap", plotOutput("heatmap", width = "800px", height = "800px")), tabPanel("Summary", verbatimTextOutput("summary")))))
Thank you in advance. 

Vincent

unread,
Feb 15, 2013, 2:29:41 PM2/15/13
to shiny-...@googlegroups.com
The block needs to be in sidebarPanel. This should work:

library(shiny)

# Define UI for application that plots random distributions 
shinyUI(

  pageWithSidebar(

    # Application title
    headerPanel("Clustering results"),
    
    # Sidebar with a slider input for number of observations
    sidebarPanel(
      tags$head(
        tags$style(type="text/css", "select { max-width: 200px; }"),
        tags$style(type="text/css", "textarea { max-width: 185px; }"),
        tags$style(type="text/css", ".jslider { max-width: 200px; }"),
        tags$style(type='text/css', ".well { max-width: 310px; }"),
        tags$style(type='text/css', ".span4 { max-width: 310px; }")
      ),

      helpText("There are 615 experiments\n",
               "and 230595 peptides.",
               "minExp = 2, minPep = 2."),
     
      selectInput("k","Method for choosing k for SVD:", 
                  choices = c("Akaike information criteria (k = )", "Amended description length (k = )", 
                              "Percentange of var. explained = 0.5 (k = )","Percentange of var. explained = 0.8 (k = )",
                              "Percentange of var. explained = 0.95 (k = )")
      )
    ),
    
    # Show a plot of the generated distribution
    mainPanel(
      tabsetPanel(
        tabPanel("Heatmap", plotOutput("heatmap",width = "800px", height = "800px")), 
        
        
        #tabPanel("Heatmap", plotOutput("heatmap",width = "1000px", height = "900px")), 
        tabPanel("Summary", verbatimTextOutput("summary"))
      )
    )
  )
)

Ksenia Titorenko

unread,
Feb 16, 2013, 8:24:48 AM2/16/13
to shiny-...@googlegroups.com
Thank you! But still I couldn't change the size of select input. Now it is displayed as "Akaike information criteria (k", but I need "Akaike information criteria (k =  ) "
Ksenia.

Vincent

unread,
Feb 16, 2013, 11:10:50 AM2/16/13
to shiny-...@googlegroups.com
You have to change the relevant values to make things as big as you need them. See below

library(shiny)

# Define UI for application that plots random distributions 
shinyUI(

  pageWithSidebar(

    # Application title
    headerPanel("Clustering results"),
    
    # Sidebar with a slider input for number of observations
    sidebarPanel(
      tags$head(
        tags$style(type="text/css", "select { width: 400px; }"),
        tags$style(type="text/css", "textarea { max-width: 185px; }"),
        tags$style(type="text/css", ".jslider { max-width: 200px; }"),
        tags$style(type='text/css', ".well { max-width: 430px; }"),
        tags$style(type='text/css', ".span4 { max-width: 430px; }")
      ),

      helpText("There are 615 experiments\n",
               "and 230595 peptides.",
               "minExp = 2, minPep = 2."),
     
      selectInput("k","Method for choosing k for SVD:", 
                  choices = c("Akaike information criteria (k = )", "Amended description length (k = )", 
                              "Percentange of var. explained = 0.5 (k = )","Percentange of var. explained = 0.8 (k = )",
                              "Percentange of var. explained = 0.95 (k = )")
      )
    ),
    
    # Show a plot of the generated distribution
    mainPanel(
      tabsetPanel(
        tabPanel("Heatmap", plotOutput("heatmap",width = "800px", height = "800px")), 
        
        
        #tabPanel("Heatmap", plotOutput("heatmap",width = "1000px", height = "900px")), 
        tabPanel("Summary", verbatimTextOutput("summary"))
      )
    )
  )
)

Andrew Gormley

unread,
Mar 26, 2013, 10:03:03 PM3/26/13
to shiny-...@googlegroups.com
Which of these change a numericInput box - none of them seem to affect the size of mine...
Also is there a specified way of setting the width of tabsetPanels?
Thanks
Andrew

Victor Kryukov

unread,
Apr 3, 2013, 11:41:36 PM4/3/13
to shiny-...@googlegroups.com
Vincent, thanks a lot of this tip - it solved one of my problems (max-width: 250px works OK for me). Now my other problem is that when I increase the width of my browser window, the tablet panel (span8) stays at ~65% of the width of the browser window and therefore I have some empty space on the right. Is there an easy way to make span8 take all the remaining space?

Alex Brown

unread,
Apr 6, 2013, 3:12:48 AM4/6/13
to shiny-...@googlegroups.com
The convenience utilities textInput, selectInput and friends just generate HTML.  You can always make your own from tags$div or similar, and then you can provide classes and ids to your heart's content.

The same goes for sidebarPanel, mainPanel and friends.

-Alex


On Wednesday, January 30, 2013 2:39:43 AM UTC-8, Vincent wrote:

Kirill Savin

unread,
Jul 11, 2013, 11:27:54 PM7/11/13
to shiny-...@googlegroups.com
Maybe the topic is obsolete, but here is a set of CSS tags to make fixed-width sidebar panel (set 275px wide) and flexible main panel (fills width to the right). Use standard page with sidebar; copy-paste the code and save as *.css file; add tags$link(rel="stylesheet", type="text/css", href="filename.css")into tags$head


.row-fluid {
    padding-left: 275px;
    box-sizing: border-box;
    -moz-box-sizing: border-box;
}
.row-fluid .span4 {
    position: relative;
    float:left;
    width: 275px;
    right: 285px;
    margin-right: -275px;
}
.row-fluid .span8 {
    float: right;
    position: relative;
    padding-left: 10px;
    padding-right: 10px;
    width: 100%;
}
.well {
    padding-left: 15px;
    padding-right: 15px;
    margin-bottom: 0px;
    width: auto;
}
textarea, .jslider, select{
    width: 100%;
}
input{
    width: 230px;
}

Stéphane Laurent

unread,
Sep 11, 2013, 5:32:29 PM9/11/13
to shiny-...@googlegroups.com
The width fills well to the right but when I change the values of 275px and 285px, nothing changes. I'd like to reduce the width of the sidebar panel.

Kirill Savin

unread,
Sep 11, 2013, 7:23:41 PM9/11/13
to shiny-...@googlegroups.com
It changes. Set to 200px. The only problem with this approach is that title on header panel does not align to the left. Who wants titles anyway :-). I leave title property blank and set windowTitle to the name of the app, so that I still have the name of the app on browser tab.
headerPanel(title = "", windowTitle = "Enter your title here")

.row-fluid {
    padding-left: 190px;

    box-sizing: border-box;
    -moz-box-sizing: border-box;
}
.row-fluid .span4 {
    position: relative;
    float:left;
    width: 190px;
    right: 200px;
    margin-right: -190px;

}
.row-fluid .span8 {
    float: right;
    position: relative;
    padding-left: 10px;
    padding-right: 10px;
    width: 100%;
}
.well {
    padding-left: 15px;
    padding-right: 15px;
    margin-bottom: 0px;
    width: auto;
}
textarea, .jslider, select{
    width: 100%;
}
/* inputs have to be sized separately */
input{
    width: 145px;
Message has been deleted

Frederic Commo

unread,
Apr 2, 2014, 9:42:43 AM4/2/14
to shiny-...@googlegroups.com
Thanks for the trick. It works fine.

But I'm a newbie in css.
What would be the syntax in order to change the font-size inside selectInput() or textInput() ?

For other newbies, this command allows to modify also buttom sizes, spacing and text:

tags$style(type="text/css", "label.radio { display: inline-block; font-size:18px; margin-left: 18px;}",
                     ".radio input[type=\"radio\"] { float: none; width:18px; height:18px; }")

Thanks


On Wednesday, January 30, 2013 2:39:43 AM UTC-8, Vincent wrote:

Stéphane Laurent

unread,
Apr 2, 2014, 12:53:21 PM4/2/14
to shiny-...@googlegroups.com
About the size of the sidebar, it is nice to do:

                     sidebarPanel(
                       style="min-width:235px;max-width:375px", 
                       ..........

Frederic Commo

unread,
Apr 2, 2014, 6:05:33 PM4/2/14
to shiny-...@googlegroups.com
I got the element names, using firebug

These lines adjust font and box sizes on selectInput() and textInput()

          tags$style(type="text/css", "select.shiny-bound-input { font-size:20px; height:35px;}"),
          tags$style(type="text/css", "input.shiny-bound-input { font-size:20px; height:35px;}"),

Fred

Nicholas Crookston

unread,
Apr 5, 2014, 8:56:36 PM4/5/14
to shiny-...@googlegroups.com
Fred (et al):

I've tried for hours to get the selectInput widget to change size (font and some other features) and I tried the suggestion posted by Fred (thanks).

Consider the ur.R code in the shiny examples "02_text". I tried Freds code and I've also tried the following:
 
    tags$style(type="text/css", "#dataset { font-size:10px; height:12px; width:50px;}"),
    tags$style(type="text/css", "#obs     { font-size:10px; height:12px; width:50px;}"),

Fred's code and my code changes the input widget (the one where the number of observations is entered), but for some reason I can't get selectInput attributes to change.  Any suggestions?

Laurent Franckx

unread,
Apr 10, 2015, 2:22:46 PM4/10/15
to shiny-...@googlegroups.com
Hello

What line would I need to add to modify the maximum width of a textInput() field?

Thx
Laurent

Sergio Fernández

unread,
Jan 27, 2016, 7:21:24 AM1/27/16
to Shiny - Web Framework for R
I would like to ask something related. 

I want to resize a verbatimTextOutput() that is so small in my shiny webpage.... How could I do that?

Thank you!
Reply all
Reply to author
Forward
0 new messages