I have a Shiny application I'm working on. Part of it involves generating a plot using ggplot2. There are quite a lot of variables, so I'd like it to be able to scroll pretty widely so that it's readable. Originally I tried to adjust the size using plotOutput("plot1", width = X) (where x is some number), and I can make it work like this if I know exactly what my plot1 is going to look like. The thing is, there will eventually be filters that will affect how big plot1 is, so I can't predefine it.
What I'd like to be able to do is somehow tell R to say, "use ggplot2 to make a barchart where the bars are all x units wide, and make the plot as big as it needs to be."
Here is the code in server.r that generates the plot:
output$plot1 <- renderPlot({
ggplot(data = dat, aes(x = foo)) + geom_bar(stat="bin")
+facet_grid(~bar, scales = "free_x", space = "free")
and then in ui.r I call it like I did above:
plotOutput("plot1", width = X)
Specifically what's happening is that 'facet_grid' is splitting the plot up into different groups, and the user will have the option of deciding what/how many groups there are.
A possible workaround I thought of would involve somehow trying to count the number of bars that would be present and then coming up with a function to figure out how big X would be. In a regular R session this would be pretty easy, but in Shiny, I would need to be able to calculate a variable in server.r and use it in ui.r, and I'm a bit confused on how to do that.
EDIT: I may have figured out a workaround by instead of doing a plot, casting the plot to an image and displaying the image. Now I just have to figure out how to make the image full-size, instead of having shiny scale it to fit the window. Any advice on that would be appreciated.