4

I am using set_options(width = "auto", height = "auto", resizable=FALSE) to auto-size a ggvis chart. It works fine when the chart is the only element in the column function, but if I add other elements, the chart keeps resizing to the infinite. I know html has a max-height attribute that probably would prevent this behavior, but this attribute is not available in ggivs.

Here is my example:

ui.R

library(shiny)
library(ggvis)
shinyUI(fluidPage(

  fluidRow(titlePanel("Old Faithful Geyser Data")),

    fluidRow(
          column(12,
                 tags$h1("hello"),
                 ggvisOutput('test1')
                 )
    )
   )
  )

server.R

library(shiny)
library(ggvis)
shinyServer(function(input, output) {

  cars %>% 
  ggvis(~speed) %>% 
    layer_bars() %>% 
    set_options(width="auto", height= "auto", resizable=FALSE) %>% 
  bind_shiny("test1", "test1_ui")
})

I am using firefox 47.0

Dambo
  • 3,318
  • 5
  • 30
  • 79

1 Answers1

1

According to the documentation:

Note that height="auto" should only be used when the plot is placed within a div that has a fixed height; if not, automatic height will not work, due to the way that web browsers do vertical layout.

We can accomplish this by modifying your ui.R, setting a fixed height for the div which contains the ggvis plot. For example:

shinyUI(fluidPage(

  fluidRow(titlePanel("Old Faithful Geyser Data")),

  fluidRow(
    column(12,
           tags$h1("hello"),
           div(style='height:400px;', # We define a fixed height of 400px
           ggvisOutput('test1')
           )

    )
  )
)
)
mtoto
  • 23,919
  • 4
  • 58
  • 71
  • Thanks, but why adding a second element in `column()` makes the difference? 'Cause `height=auto` works fine if the ggvisOutput is the only element (and by the way, it is probably more straightforward to set the height in `set_option`). – Dambo Jul 09 '16 at 21:32
  • 1
    When you are adding the second element in `column()`, you are pushing the plot further down, which causes `.... (insert the above reason mentioned by @mtoto)` and hence either add a `div` element or set `height` equal to something in `set_option` (it won't matter if the dimensions won't fit the page, you can scroll) – Sumedh Jul 10 '16 at 01:46