Shiny Dashboard works locally, but succumbs to an error when deployed on shinyapp.io or postitcloud

Hi I am at my wits end, been trying to deploy a shiny and bs4dash package on shinyapps and postitcloud for the last 3 days but it keeps coming up with an error!

The dashboard works fine locally but the moment I deploy its gone. dead.

I have tried to install all of the packages and dependencies, changed my working directory from local to cloud, pasted my code on the posit cloud r studio to deploy it. Nothing works. Help please.

My setup code is options(repos = c(CRAN ="https://cloud.r-project.org"))
#set a CRAN Mirror explicitly
setwd("~/Study/Data Visualisation/2024")

packages<-c(
"shiny", "bs4Dash", "dplyr", "readr", "plotly", "leaflet", "DT", "fresh",
"tidyverse", "rmarkdown", "tinytex", "prettydoc", "magrittr", "outliers",
"knitr", "MVN", "here", "lubridate", "data.table", "here", "rsconnect"
)

install and load packages
install_and_load <- function(pkg) {
if (!require(pkg, character.only = TRUE)) {
install.packages(pkg, dependencies = TRUE)
library(pkg, character.only = TRUE)
}
}

install and load all packages
lapply(packages, install_and_load)

Hi @pandasweets !

Sorry to hear you're having trouble! It looks like you've provided some code, but I'm not sure it's the entire shiny application you're looking to deploy. It's also formatted a little funny, using the "code block" feature would help that:

There's two things though that I can see which may be causing some trouble:

  1. you use setwd to change your working directory to a subdirectory of your home directory. Check out this page on shinyapps.io storage with some more details about why relative directories can be troublesome when deploying between environments
  2. it's not best practice to use the install.packages() command within the execution of a shiny application -- this command can take a very long time to execute depending on the environment, and can block the application from starting successfully in a reasonable time because of that. If you're deploying to shinyapps.io or posit.cloud publishing using rsconnect and/or the publishing button in the rstudio ide, that tooling actually handles identifying the packages you're using in this shiny application and ensuring those packages installed in the remote environment.

Hopefully these pointers help!
Steve

Thank you so much Steve, I tried your suggestions and got rid of the manual setwd().
I also set the packages and library to:

knitr::opts_chunk$set(echo = TRUE)

options(repos = c(CRAN ="https://cloud.r-project.org"))  
#set a CRAN Mirror explicitly


install.packages("shiny")
install.packages("bs4Dash")
install.packages("dplyr")
install.packages("readr")
install.packages("plotly")
install.packages("leaflet")
install.packages("DT")
install.packages("fresh")
install.packages("tidyverse")
install.packages("rmarkdown")
install.packages("tinytex")
install.packages("prettydoc")
install.packages("magrittr")
install.packages("knitr")
install.packages("MVN")
install.packages("here")
install.packages("lubridate")
install.packages("data.table")
install.packages("rsconnect")

library(shiny)
library(bs4Dash)
library(dplyr)
library(readr)
library(plotly)
library(leaflet)
library(DT)
library(fresh)
library(tidyverse)
library(rmarkdown)
library(tinytex)
library(prettydoc)
library(magrittr)
library(knitr)
library(MVN)
library(here)
library(lubridate)
library(data.table)
library(rsconnect)

rsconnect::setAccountInfo(name=***********deleted for annoymity) 

It still works locally but when deployed comes with the 'An error has occurred. The application failed to start, exit status 1'

Looking at the logs

Blockquote 2024-08-21T14:21:33.584351+00:00 shinyapps[12474625]: Error in match.arg(theme, themes()) :
2024-08-21T14:21:33.592598+00:00 shinyapps[12474625]: 'arg' should be one of “default”, “bootstrap”, “cerulean”, “cosmo”, “darkly”, “flatly”, “journal”, “lumen”, “paper”, “readable”, “sandstone”, “simplex”, “spacelab”, “united”, “yeti”
2024-08-21T14:21:33.599800+00:00 shinyapps[12474625]: Calls: local ... tryCatch -> tryCatchList -> tryCatchOne ->
2024-08-21T14:21:33.605649+00:00 shinyapps[12474625]: Execution halted
2024-08-21T14:21:33.611589+00:00 shinyapps[12474625]: Shiny R Markdown document exiting ...

Blockquote

The problem seems to be with the theme. I am trying to use the bs4dash package and set the theme as

plot_colour <- "#8965CD"

theme <- create_theme(
bs4dash_color(
lime = "#52A1A5",
olive = "#4A9094",
purple = "#8965CD"
),
bs4dash_status(
primary = "#E1EDED",
info = "#E4E4E4"
)
)

the only other places with theme are the yaml which I have set as

output:
prettydoc::html_pretty:
theme: cayman
highlight: github
editor_options:
markdown:
wrap: 72
runtime: shiny

Please let me know what I have done wrong and thank you for all your help

Hi Steve, hope you are well. Would you be able to help me with the follow up error?

Appreciate your help

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.