2

I am trying to make one of two plots depending on browser size (from shinybrowser) using conditionalPanel. The plots are appearing when I run the app locally but do not appear when on the shinyapps server. I have tried using different outputIDs for the conditionalPanel but it did not work. Any help would be much appreciated!

library(shiny)
library(data.table)
library(ggplot2)
library(dplyr)
library(shinyBS)
library(shinybrowser)

Data

res_df = data.frame(Average=1:50)
res_df$Specialty = rep(paste0(letters[1:25], letters[1:25]), 2)
res_df$Description_of_Test_or_Experience = rep(LETTERS[1:2], 25)

Server

server <- function(input, output) {
    
    output$res_grid_plot = renderPlot({
        
        ## test
        screen_width = get_width()
        output$width = renderText({screen_width})
        
        ## plot
        if(screen_width < 700){
            output$grid = renderText({"small"})
            p = ggplot(res_df, aes(y=Specialty, x=Description_of_Test_or_Experience, label=Average)) +
                geom_tile(color = "dodgerblue3", lwd = .15, linetype = 1, fill="white", alpha = 1) +
                geom_text(color = "black", size=3) + 
                theme_minimal() +
                theme(axis.text.y = element_text(size=9.5),
                      axis.title = element_blank())
            print(p)
            
        } else{
            output$grid = renderText({"large"})
            output$res_grid_plot_large = renderPlot({
                p = ggplot(res_df, aes(y=Specialty, x=Description_of_Test_or_Experience, label=Average)) +
                    geom_tile(color = "dodgerblue3", lwd = .15, linetype = 1, fill="white", alpha = 1) +
                    geom_text(color = "black", size=4.25) + 
                    theme_minimal() +
                    theme(axis.text.y = element_text(size=12),
                          axis.title = element_blank())
                print(p)
            })
            NULL
        }
        
        outputOptions(output, 'grid', suspendWhenHidden=FALSE)
        
    })
}

UI

ui = fluidPage(

  tabPanel("Yearly Data",
           h1("Overview"),
           
           shinybrowser::detect(),

           textOutput("width"), 
           
           conditionalPanel(condition = "output.grid == 'small'",
                            fluidRow(style='padding-top:3em;',
                                     column(12, plotOutput("res_grid_plot", height = "800px")))),

           conditionalPanel(condition = "output.grid == 'large'",
                                     column(10, offset=1, plotOutput("res_grid_plot_large", height = "800px")))))
CALee
  • 36
  • 2
  • 1
    You have nested renderPlots. Perhaps you should rethink that strategy. – YBS Apr 28 '22 at 21:12
  • @YBS I tried separating the plots and ran into the same issue where they appeared locally but not on the shinyapps server. – CALee Apr 29 '22 at 23:49

1 Answers1

0

I am not sure about my answer because I can't see any clue in the shinyapps.io logs. I think it comes from the package shinybrowser. It may not be available for the shinyapps version of R or something like that. For my local RStudio, I installed it from GitHub (see below) because of this error but I don't know if it it the same issue for shinyapps version of R.

install.packages("remotes")
remotes::install_github("daattali/shinybrowser")
PCottais
  • 46
  • 3