Black Lives Matter. Please consider donating to Black Girls Code today.
Dash Enterprise delivers an incredible 21x cost savings 💸Download the e-book!

R API Using Shiny with Tabs and ggplot graphs

Hi All

I am new to this so forgive me for my terminology.

I have started writing shiny apps and everything was working reasonably untill I tried a working shiny app with plotly. Plotly is great for formatting graphs.

So I wrote an app in R and shiny , it worked no problem…then I looked at an example with ggplot on the Plotly website , and repeated it on my pc…fine

Then I took the same code constructs and instead of using the normall ggplot command and the render plot in shint I changed it to the plotly commands ie

  1. I changed the ui commands from plotOutput to plotlyOutput and using library(plotly)…as per the example BUT: these commands are inside a tabpanel in my file
  2. in the server I traslated the normal print§ from ggplot to gg=p;p1=ggplotly(gg);print(p1) … and used library(plotly) and the renderPlotly command
  3. I left all the text panels and outputs identical.

Result :

When I ran the app , a browswer opened with the app. I have 3 tabs , one is conditional ( a graphics plot) , and the second is a text output tab, the 3rd is a graphics plot

Nothing wrong with the text tab
Both graphics tabs worked I on pressing them the correct control part or side panels came up , BUT there was no graph !!! What I could do is set the controls on the control panel , go back to the Rstudio Viewer area and intiate the external viewer push button (the one with the straight arrow in the top right ) , and it opened another tab in the browser and there was my plot…which reacted to all the plotly controls.

Therefore has anyone got a working file in shiny with plotly (using ggplot) BUT WITH TABS. (ui plus server ) ?

A second problem is when using the normal ggplot2 inside the example but using geom_smooth with method = “lm” and formula =poly(x,input$order) , or using the stat_smooth constaruct the same error and warning occurs repeatedly ie

Warning: Computation failed in stat_smooth():
object ‘weight’ not found
Warning: Computation failed in stat_smooth():
object ‘weight’ not found
Warning: Computation failed in stat_smooth():
object ‘weight’ not found
Warning: Computation failed in stat_smooth():
object ‘weight’ not found
Warning: Computation failed in stat_smooth():
object ‘weight’ not found
Warning: Computation failed in stat_smooth():
object ‘weight’ not found
Warning: Computation failed in stat_smooth():
object ‘weight’ not found
Error in order(df$order) : argument 1 is not a vector

This does not happen in shiny without plotly ???

The main question is , if I use tabs in shiny , I cant get a normal output to the browser with the plotly editing facilityies.

If anyone is prepared to help I will gladly post my code…But perhaps there is a straight answer. If this should work please post me a working example with

(shiny , ggplot2, plotly and tabbeed output in shiny )

Many Thanks
Graham

Hi ! Are you able to share your ui.R and server.r files by any chance? And any associated data with it as well?

thanks