I implemented a simple stack line graph in Rshiny. The file read from the .csv file added to project folder. The graph is working and displayed fine while running the application from Rstudio. But once the app is published in www.shinyapps.io it is throwing an error Error in ggplot2: object 'data' not found
. Could anyone help me why this is happening after app deployment. Thanks in advance.
ui.R
library(shiny)
library(shinydashboard)
library(ggplot2)
library(dplyr)
library(RColorBrewer)
data <- read.csv("pie.csv", header = TRUE)
recommendation <- read.csv("recommendation.csv", header = TRUE)
shinyUI(
dashboardPage(
dashboardHeader(title = "ONE", #dropdownMenuOutput("msgOutPut")
dropdownMenu(type = "message",
messageItem(from = "Finance Update", message = "we are on threshold",icon = icon("dollar"),time = "10:00am"),
messageItem(from = "Sales Update", message = "Sales are at 55%", icon = icon("bar-chart"),time = "1:00pm"),
messageItem(from = "Sales Update", message = "Sales meeting at 6pm on Monday", icon = icon("handshake-o"),time = "6:00pm")
),dropdownMenu(type = "tasks", badgeStatus = "warning",
notificationItem(icon = icon("users"), status = "info",
"5 new members joined today")
)),
dashboardSidebar(
#sliderInput("bins","Number of Breaks",1,100,50),
sidebarMenu(
menuItem("Summary", tabName = "Summary", icon = icon("dashboard")),
menuItem("ASupport", tabName = "AppSupport", icon = icon("tablet")),
menuItem("InSupport", tabName = "finance", icon = icon("fax")),
menuItem("SeProductivity", tabName = "dashboard", icon = icon("file"))
)),
dashboardBody(
# frow1 <- fluidRow(
# infoBoxOutput("progressBox"),
# infoBoxOutput("approvalBox")
# ),
tabItems(
tabItem(tabName = "dashboard",
h1("Service Productivity"),
fluidRow(
# box(plotOutput("histogram"))
box(
title = "Left Shift Productivity"
,status = "primary"
,solidHeader = TRUE
,collapsible = TRUE
,plotOutput("pieChart", height = "300px")
),
box(
title = "Degree of Automation"
,status = "primary"
,solidHeader = TRUE
,collapsible = TRUE
,plotOutput("degreeOfAutomation", height = "300px")
),
box(
title = "Service Cost Efficiency"
,status = "primary"
,solidHeader = TRUE
,collapsible = TRUE
,plotOutput("serviceCostEfficiency", height = "300px")
)
)),
tabItem(tabName = "finance",
h1("Digital Infra and Operations Metrics"),
fluidRow(
box(
title = "Availability"
,status = "primary"
,solidHeader = TRUE
,collapsible = TRUE
,plotOutput("revenuebyPrd", height = "300px")
),
box(
title = "Backup Success Rate"
,status = "primary"
,solidHeader = TRUE
,collapsible = TRUE
,plotOutput("backupsuccessrate", height = "300px")
)
)
),
tabItem(tabName = "sales",
h2("Service Cost efficiency")
),
tabItem(tabName = "Summary",
h2("Summary")
),tabItem(tabName = "AppSupport",
h2("App Support")
)
)
)
)
)
server.R
library(shiny)
library(shinydashboard)
shinyServer(function(input,output){
output$progressBox <- renderInfoBox({
infoBox(
"Sales", paste0("75", "%"), icon = icon("usd"),
color = "purple"
)
})
output$approvalBox <- renderInfoBox({
infoBox(
"Satisfaction", "90%", icon = icon("thumbs-up", lib = "glyphicon"),
color = "yellow"
)
})
output$histogram <- renderPlot({
hist(faithful$eruptions, breaks = input$bins)
})
output$hist <- renderPlot({
hist(faithful$eruptions, breaks = input$bins)
})
output$pieChart <- renderPlot({
colors = c("red", "yellow", "green", "violet", "orange")
pie(table(pieChartValues$Shift),col=colors)
legend(.9, 1, legend = pieChartValues$Shift, cex = 0.7, fill = colors)
})
output$serviceCostEfficiency <- renderPlot({
ggplot() + geom_area(data=sujith, aes(x=year, y=cost, fill=z)) +
guides(fill = guide_legend(reverse=TRUE))
# ggplot(data = diamonds, aes_string(x=Year, y=Value, fill=Sector)) +
# geom_area(colour="black", size=.2, alpha=.4) +
# scale_fill_brewer(palette="Greens", breaks=rev(levels(Sector)))
})
output$revenuebyPrd <- renderPlot({
ggplot(data = recommendation,
aes(x=Product, y=Revenue, fill=factor(Revenue))) +
geom_bar(position = "dodge", stat = "identity") + ylab("") +
xlab("") + theme(legend.position="bottom"
,plot.title = element_text(size=15, face="bold")) +
ggtitle("") + labs(fill = "")
})
output$degreeOfAutomation <- renderPlot({
ggplot(data = recommendation,
aes(x=Product, y=Revenue, fill=factor(Revenue))) +
geom_bar(position = "dodge", stat = "identity") + ylab("") +
xlab("") + theme(legend.position="bottom"
,plot.title = element_text(size=15, face="bold")) +
ggtitle("") + labs(fill = "")
})
output$backupsuccessrate <- renderPlot({
ggplot(data = recommendation,
aes(x=Product, y=Revenue, fill=factor(Revenue))) +
geom_bar(position = "dodge", stat = "identity") + ylab("") +
xlab("") + theme(legend.position="bottom"
,plot.title = element_text(size=15, face="bold")) +
ggtitle("") + labs(fill = "")
})
output$msgOutPut <- renderMenu({
msgs <- apply(read.csv("messages.csv"),1,function(row){
messageItem(from = row[["from"]],message = row[["message"]])
})
dropdownMenu(type = "messages", .list = msgs)
})
})