Google chart resize when browser size change

286 views
Skip to first unread message

Caixia Huang

unread,
Mar 23, 2017, 5:45:49 PM3/23/17
to Shiny - Web Framework for R
I know that when we use plotoutplot, we can set height and weight to "auto". Then the plot will resize automatically when the size of the windows change.

But I am using google chart, I'll need to use htmlOutput, which won't resize the chart automatically.

I figured out a way to do this:
1. Create a fake bar plot, and set the height = 0.1, so the plot won't show up.
2. Then I use session$clientData$output_barplot_width in rendergvis:

```
output$image_pie <- renderGvis({
    session$clientData$output_fakeplot_width
    gvisPieChart(data(), labelvar = "Image", numvar = "count",
                 options = list( height = 500))
  })
  
```

This works nice on my first tabpage. But when I tried to do the same thing in my second tabpage, it won't work. The google chart won't show up. Then I somehow add something and move something unimportant, it works.
Now I am creating my third tabpage, this problem happen again....... It works sometimes when you move something in the layout..... 

Is there anyone know what happen? Or other better way to achieve this?

Caixia Huang

unread,
Mar 23, 2017, 5:57:24 PM3/23/17
to Shiny - Web Framework for R
For example, I add a textoutput in the same page, it works and google charts will show up.

output$summary <- renderText({
    session$clientData$output_fakeplot2_width
  })

in ui: verbatimTextOutput("summary")

If I remove this text output, it won't work..

Joe Cheng

unread,
Mar 23, 2017, 6:23:27 PM3/23/17
to Caixia Huang, Shiny - Web Framework for R
Does it change if you set the height to 1 instead of 0.1?

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/5b27027a-5682-4664-b155-29958d4f87ae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Caixia Huang

unread,
Mar 23, 2017, 6:37:38 PM3/23/17
to Joe Cheng, Shiny - Web Framework for R
If I change height to 1. The google chart will show up. But there will be a warning error message: figure margins too large.
--
Caixia Huang

Joe Cheng

unread,
Mar 23, 2017, 7:47:41 PM3/23/17
to Caixia Huang, Shiny - Web Framework for R
Why not set the height to 500?

Caixia Huang

unread,
Mar 23, 2017, 9:30:29 PM3/23/17
to Joe Cheng, Shiny - Web Framework for R
Because I don't want the plot show up. I don't have "regular" r plot in my project, all the plots are googlevis chart. So I have to make a fake bar plot in order to use the Session$clientdata$output_plot_width call to build a dependency on the bar plot width. I set the height to 0.1 so it won't show up.

Joe Cheng

unread,
Mar 23, 2017, 11:05:47 PM3/23/17
to Caixia Huang, Shiny - Web Framework for R
Oh now I understand. You should be able to just omit the output$plot definition on the server side altogether--just the existence of the plotOutput ought to be enough.

Caixia Huang

unread,
Mar 23, 2017, 11:22:20 PM3/23/17
to Joe Cheng, Shiny - Web Framework for R
It works!!!! Thanks!!!

Caixia Huang

unread,
Mar 24, 2017, 10:56:35 AM3/24/17
to Joe Cheng, Shiny - Web Framework for R
So it worked last night. But this morning it won't work. The plots won't show up again. I have three tab page in my dashboard. I use this method in every tab page. It's fine in two pages. But it won't work in one page. Sometimes the plot show up and sometimes don't. And when it shows up, I tried to make the browser windows smaller, then it disappeared. Looks like this method is very unreliable. Is there any thought? 

Joe Cheng

unread,
Mar 24, 2017, 11:33:33 AM3/24/17
to Caixia Huang, Shiny - Web Framework for R
Can you send us a reproducible example?

Caixia Huang

unread,
Mar 24, 2017, 5:16:13 PM3/24/17
to Joe Cheng, Shiny - Web Framework for R
Thanks Joe. I think I figured out what's wrong. In order to have session$ClientData$output_fakeplot_width work, you'll have to set a fix height for every box in that page. Otherwise, it will lead to some problems (the html plot output sometimes show up and sometimes don't).  But I can't explain why. 

I put an example here to see if you could explain this. This dashboard has three tabs. In tab three, if you don't include box4 (a data table), the plots will show up when you run it, without setting the height of box3. But if you make the browser windows smaller, the plots will disappear. If you include box4 in ui, you will have to set the height of box3, otherwise the plots won't show up at all. 

Thanks!

Caixia Huang

It works!!!! Thanks!!!


To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discuss+unsubscribe@googlegroups.com.
--
Caixia Huang
--
Caixia Huang
--
Caixia Huang
server.r
ui.r
Reply all
Reply to author
Forward
0 new messages