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")))))