Shiny App | Deployment | getting error while deploying my app to shinyapps.io

Hi All,

1.) I am getting error while deploying my app to shinyapps.io server. I am added the screen shot of error.

2.) The data set which i am using for the app is on my local machine. Can i use the data from my local machine for the server shinyapps.io? Also do i need to keep local machine running always?

Can anyone help me on this.
Any help would appreciated.

1 Like

You can upload your own data along with your app to shinyapps.io (it needs to be under the same folder and you need to use relative paths instead of absolute ones), once your data file is uploaded is independent of your local machine so not need for keep it running.

Thanks for your replay.

I attached the app.R file and my .csv file while publishing my app.
but still getting the below error as:

================
An error has occurred
The application failed to start (exited with code 1).

Loading required package: dplyr
Warning in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called ‘dplyr’
Warning in install.packages(x, dependencies = TRUE) :
'lib = "/opt/R/3.5.1/lib/R/library"' is not writable
Error in value[3L] : unable to install packages
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne ->
Execution halted

=============================

Could you share the code of your app? It's hard to tell what is your problem without more information

Yes andresrce,

below is sample code

Thanks for help.

===================================================================
# Sales Data Analysis Report !

#specify the packages of interest
packages = c("dplyr", "ggplot2","gridExtra","shiny","shinydashboard",
             "DT", "numform", "shinyBS")


#use this function to check if each package is on the local machine
#if a package is installed, it will be loaded
#if any are not, the missing package(s) will be installed and loaded
package.check <- lapply(packages, FUN = function(x) {
  if (!require(x, character.only = TRUE)) {
    install.packages(x, dependencies = TRUE)
    library(x, character.only = TRUE)
  }
})
# Clear the Global Environment
rm(list = ls())


"Sales Data Analysis Report !"
# Clear the Globle Enviroment
rm(list = ls())

ui = dashboardPage(
  dashboardHeader(title = HTML(paste0(icon('cubes')),"Sales Data Analysis Report !"), 
                  titleWidth = 310 
  ),
  dashboardSidebar(
    tags$footer(p("Ganesh Patil"),
                p("email@gmail.com"), align = "right", style = "
                position:absolute;
                bottom:0;
                width:100%;
                height:50px; /* Height of the footer */
                color: white;
                padding: 10px;
                
                z-index: 1000;"
    ),
    sidebarMenu(
      br(),
      menuItem("Dashboard-1",tabName = "dashboard_1",icon = icon("dashboard"))
      

    )
    
    ),
  dashboardBody(
    tabItems(
      tabItem(tabName = "dashboard_1",
              fluidPage(
                fluidRow(
                  infoBoxOutput("numb_of_usr"),
                  infoBoxOutput("numb_of_Prod"),
                  infoBoxOutput("Total_sale")
                ),
                fluidRow(
                  box(width = 4,height = 300, title = "Percent of Sales by Gender",status = "primary",
                      solidHeader = TRUE, collapsible = TRUE,
                      plotOutput("plot1")),
                  box(width = 4,height = 300, title = "Sales ($) by Gender",status = "primary",
                      solidHeader = TRUE, collapsible = TRUE,
                      plotOutput("plot2")),
                  box(width = 4,height = 300, title = "Sales ($) by Age Group",status = "primary",
                      solidHeader = TRUE, collapsible = TRUE,
                      plotOutput("plot3"))
                )
              )
      )
)

)
    )


server = function(input , output){
  
  # Read the csv data file
  sale_data =data.table::fread("D:/Study Material/R shiny/Sales Data Analysis/data.csv",
                                 colClasses = c(rep("character", 2),"factor",rep("character", 8),"integer"),
                                 stringsAsFactors = FALSE)
  
 
  # InfoBox - Distinct Number of Users  
  output$numb_of_usr = renderInfoBox({
    infoBox(
      "Number of Users", prettyNum(sale_data%>%distinct(User_ID)%>%count(), big.mark = ","), 
      icon = icon("address-card"),fill = FALSE
    ) 
  })
  
  # InfoBox - Distinct Number of Products (Product Count)
  output$numb_of_Prod = renderInfoBox({
    infoBox(
      "Number of Products", prettyNum(sale_data%>%distinct(Product_ID)%>%count(), big.mark = ","),
      color = "purple", icon = icon("list"),fill = FALSE
    ) 
  })
  
  # InfoBox - Total Sale
  output$Total_sale = renderInfoBox({
    infoBox(
      "Total Sale ($)", paste0("$", "   ", prettyNum(sale_data%>%select(Purchase)%>%summarise(Total = sum(as.numeric(Purchase))), big.mark = ",")),
      color = "yellow", icon = icon("thumbs-up", lib = "glyphicon"),fill = FALSE
    ) 
  })
  
  # Pie Chart - Percent of Seles by Gender
  output$plot1 = renderPlot(width = "auto", height = 230,{ 
    sales_by_gender_pie = sale_data%>%group_by(Gender)%>%summarise(sales_1 = sum(as.numeric(Purchase)))%>%
      mutate( per_sale  = round((sales_1/sum(sales_1))*100,2))%>%
      ggplot( aes(x=factor(1), y=Gender, fill=factor(prettyNum(sales_1,big.mark = ",")))) +
      geom_bar(stat="identity") +
      geom_text(aes(x= factor(1), label = paste0(Gender, "  ", paste0(per_sale, "%"))), size=5) +  # note y = pos
      # facet_grid(facets = .~Gender, labeller = label_value) +
      coord_polar(theta = "y")+
      theme(axis.title = element_blank(),
            axis.ticks = element_blank(),
            axis.text = element_blank())+
      theme_void() + 
      scale_fill_discrete(name = "Sale ($)");
    sales_by_gender_pie
    
  })
  
  # Sales ($) by Gender
  output$plot2 = renderPlot(width = "auto", height = 230,{ 
    
    sales_by_gender_bar = sale_data%>%group_by(Gender)%>%summarise(sales_1 = sum(as.numeric(Purchase)))%>%
      mutate( per_sale  = round((sales_1/sum(sales_1))*100,2))%>%
      ggplot( aes(x=Gender, y=sales_1, fill =  Gender)) +
      geom_bar(stat="identity") + 
      geom_text(aes(label = prettyNum(sales_1, big.mark = ",")), vjust = 0 ) + 
      theme(axis.title = element_blank(),
            axis.ticks = element_blank(),
            axis.text = element_blank()) + 
      theme_void();
    sales_by_gender_bar 
    
  })
  
  # Sales by Age group
  output$plot3 = renderPlot(width = "auto", height = 230,{ 
    sales_by_age = sale_data%>%group_by(Age,Gender)%>%summarise(sales_by_age = sum(as.numeric(Purchase)))%>%
      ggplot(aes(x = Age, y = sales_by_age, fill = Gender)) + 
      geom_bar(stat = 'identity', position = 'dodge') + 
      theme_classic();
    sales_by_age + theme(legend.position="bottom", axis.text.x = element_text(angle = 90, hjust = 1)) + 
      labs(y = "Sale ($)")
    
  })
  
  # Sales ($) by City
  output$plot4 = renderPlot(width = "auto", height = 230,{ 
    sales_by_city_pie = sale_data%>%group_by(City_Category)%>%summarise(sales_by_city = sum(as.numeric(Purchase)))%>%
      mutate( per_sale_city  = round((sales_by_city/sum(sales_by_city))*100,2))%>%
      ggplot( aes(x=factor(1), y=City_Category, fill=factor(prettyNum(sales_by_city,big.mark = ",")))) +
      geom_bar(stat="identity") +
      geom_text(aes(x= factor(1), label = paste0(City_Category, "  ", paste0(per_sale_city, "%"))), size=5) +  # note y = pos
      # facet_grid(facets = .~Gender, labeller = label_value) +
      coord_polar(theta = "y")+
      theme(axis.title = element_blank(),
            axis.ticks = element_blank(),
            axis.text = element_blank()) + 
      theme_void() + 
      scale_fill_discrete(name = "Sale ($)");
    
    sales_by_city_pie  
    
  })
  

}

shinyApp(ui = ui , server  = server )
=====================================================================

This is the problem, as I said before, you can't use absolute paths on deployed shiny apps, you have to use relatively paths.

Also, there is no need to include the install commands in your app, just load the libraries.

Per the documentation, do not explicitly install packages in your code. Instead reference them with library() calls. They will be automatically installed by the server, and match the version you have locally.

1 Like

Thanks for your help andrescs.

I deploy the app successfully on Shinyapps.io server.Now it running.

Thanks for the help josh.

1 Like

This topic was automatically closed 54 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.