Reaching the maximum height of shiny apps.io server with very long faceted plot

ggplot2
shiny
shinyappsio
rstudioserver

#1

I have a fluidPage layout simplified to this:

ui <- fluidPage(
  div(h6("Built by ", tags$a(href="https://www.linkedin.com/in/kamille-elvstrøm-krause-3b1153109/", "Kamille Elvstrøm Krause"), " & ", tags$a(href="https://www.linkedin.com/in/carina-skaarup-3b049364/", "Carina Skaarup")),
      tags$a(href = "http://tropicalpharmacology.com", img(src = "TPL_logo_black.jpg", width = "479px", height = "100px")),
      tags$a(href = "http://www.dtu.dk/english/education", img(src = "DTU_logo.jpg", width = "220px", height = "100px", align = "right"))),
  
  navbarPage("",
             tabPanel("About")
    
             tabPanel("STAB Profiles",
                      fluidRow(
                        column(width = 12,
                               h2("Snake Toxin and Antivenom Binding Profiles"),
                               br(),
                               fluidRow(
                                 column(width = 3,
                                        h3("Binding Profile Specifics"),
                                        selectInput(...)),
                                 
                                 column(width = 9,
                                        tabsetPanel(type = "tabs",
                                                    tabPanel(title = "Binding Profile",
                                                             fluidRow(
                                                               column(width = 9,
                                                                      # Plot (facet):
                                                                      br(),
                                                                      uiOutput(outputId = "ui_plot"),
                                                                      style = 'height:800px; overflow-y: scroll'),
                                                               column(width = 3,
                                                                      # Legend:
                                                                      br(),
                                                                      uiOutput(outputId = "ui_legend"))
                                                             )
                                                    ),
                                                    
                                                    tabPanel(title = "Chosen Variables Data Table",
                                                             br(),
                                                             downloadButton('downloadData1', 'Download Data'),
                                                             br(),
                                                             br(),
                                                             dataTableOutput(outputId = "table1"),
                                                             style = 'height:800px; overflow-x: scroll; overflow-y: scroll'),
                                                    
                                                    tabPanel(title = "Chosen Data Points Data Table",
                                                             br(),
                                                             downloadButton('downloadData2', 'Download Data'),
                                                             br(),
                                                             br(),
                                                             dataTableOutput(outputId = "table2"),
                                                             style = 'height:800px; overflow-x: scroll; overflow-y: scroll')
                                        )
                                 )
                               )
                        )
                      )
             )
  )
)

This is just to give you an idea of the size (height) of my UI.

I have a VERY long script so I'm really trying to simplify!

My problem is with the "# Plot (facet):" part.

The server part of the "uiOutput(outputId = "ui_plot")" call looks like this:

server <- function(input, output, session) {
  ...
  
  values <- reactiveValues()
  plot_height <- function() {
    values$facet_count <- as.numeric(length(unique(data_subset()$UniprotID)))*200
    return(values$facet_count)
  }
  
  output$plot <- renderPlot({
    ggplot(data = data_subset(), aes(x = Position_start, y = Signal, color = Antivenom)) +
      geom_point() + geom_line() +
      facet_wrap(~UniprotID, ncol = 1)
  })
  
  output$ui_plot <- renderUI({
    plotOutput("plot",
               height = plot_height())
  })
}

Notice the height of each facet plot is set to 200 px in the "plot_height" function.

I would like this height to be 350 px as the plots otherwise become to small.

BUT, now here is the problem:

The data_subset process can maximum generate 80 faceted plots with the selecting inputs I have, but when this happens the figure will only display at a maximum facet plot height of 200 px when the app is published to the shinyapps.oi server. It works just fine when running the app locally in RStudio. Any number set above 200 will display the following error message in the published app, where the plot was supposed to be:
"Error: An error has occurred. Check your logs or contact the app author for clarification."

My conclusion is that there must be a maximum total height of the page the online shiny server can portray, and if your plot exceeds this it cannot show the plot.

80 plots times a height of 200 px gives a total height of 16000 px for the total ggplot2 figure, which apparently is the max height it can show when published on the shinyapps.oi server.

I have published the app with the height of 200 px per facet on this link:
https://snake.shinyapps.io/STAB_Profiles/

And the app with the height of 350 px per facet on this link:
https://snake.shinyapps.io/Snake_App/

To get the maximum amount of plots choose "Naja" in the "Snake Genus" drop-down menu.

The only difference between the two published apps is the facet height, and one works just fine while the other one portrays error messages at three genus choices when species is not specified.

My question is:
Is there any way to get around this problem so I can get more height on each facet plot, without reducing the number of facet plots in the figure?


#2

You didn't include what the error in the logs was, perhaps that would indicate the nature of the fix needed?


#3

Here is the log errors:

2018-09-12T13:40:39.789263+00:00 shinyapps[411342]: Listening on http://127.0.0.1:43790
2018-09-12T13:40:51.476088+00:00 shinyapps[411342]: Advarsel i pngfun(filename = filename, width = width, height = height, res = res,  :
2018-09-12T13:40:51.476090+00:00 shinyapps[411342]:   cairo error 'invalid value (typically too big) for the size of the input (surface, pattern, etc.)'
2018-09-12T13:40:51.490628+00:00 shinyapps[411342]:   135: pngfun
2018-09-12T13:40:51.490632+00:00 shinyapps[411342]:   134: startPNG
2018-09-12T13:40:51.490635+00:00 shinyapps[411342]:   119: <reactive:plotObj>
2018-09-12T13:40:51.478485+00:00 shinyapps[411342]: Advarsel: Error in pngfun: unable to start device 'png'

#4

Searching for that error indicates you might be trying to use too much memory, in which case you could try a larger instance size or switch to SVG.

Others with more experience with ggplot might be able to offer additional insight.