ggvis icon indicating copy to clipboard operation
ggvis copied to clipboard

At least some legend properties go missing when rendered in Shiny

Open ellisp opened this issue 11 years ago • 4 comments

The well known problem of legends rendering on top of eachother can be fixed by setting at least one of the legends' properties, like

  mtcars %>%
  ggvis(x = ~wt, y = ~mpg, fill = ~gear, shape = ~as.factor(cyl) ) %>%
  layer_points() %>%
  add_legend("fill", properties = legend_props(legend = list(y = 150))) %>%
  add_legend("shape", properties = legend_props(legend = list(y = 50)))

Which renders fine:

legend_ok

But when you render the same object in a Shiny the legends start in the correct positions, then whisk back up to the top right corner on top of eachother: https://peteratmbie.shinyapps.io/legend_props_eg/

ellisp avatar Jan 15 '15 18:01 ellisp

Can you supply the source for your shiny app?

wch avatar Jan 21 '15 20:01 wch

Sorry

https://github.com/nz-mbie/mbie-shiny-basic-egs/tree/master/legend_props_eg

or, for better convenience, pasted in here:

library(ggvis)
library(shiny)

server <- function(input, output) {
   mtcars %>%
      ggvis(x = ~wt, y = ~mpg, fill = ~gear, shape = ~as.factor(cyl) ) %>%
      layer_points() %>%
      add_legend("fill", properties = legend_props(legend = list(y = 150))) %>%
      add_legend("shape", properties = legend_props(legend = list(y = 50))) %>%
      bind_shiny("LegendProb") 

}

ui <- shinyUI(fixedPage(

   # Application title
   titlePanel("Legend properties go missing"),

   ggvisOutput("LegendProb"),

   p("The legends are displaced (y = 50 and y = 150) in a straight R session, but
                when rendered in Shiny they move both back up to the top right corner.")
   )
)

shinyApp(ui = ui, server = server)

...

Sent from my HTC

----- Reply message -----
From: "Winston Chang" <[email protected]>
To: "rstudio/ggvis" <[email protected]>
Cc: "Peter Ellis" <[email protected]>
Subject: [ggvis] At least some legend properties go missing when rendered in Shiny (#347)
Date: Thu, Jan 22, 2015 9:43 AM

Can you supply the source for your shiny app?

&mdash;
Reply to this email directly or view it on GitHub.

ellisp avatar Jan 22 '15 04:01 ellisp

Brief workaround that at least works on my system: add "set_options(duration=0) %>%" as follows

.... add_legend("fill", properties = legend_props(legend = list(y = 150))) %>% add_legend("shape", properties = legend_props(legend = list(y = 50))) %>%

set_options(duration = 0) %>%

bind_shiny("LegendProb") } ...

awnmstp avatar Jul 16 '15 05:07 awnmstp

I experience the same behavior with multiple legends.

mbacou avatar Aug 09 '15 03:08 mbacou