I am having issues when trying to publish my Shiny app.
Here is the code for the app I published:
UI:
library(shiny)
library(ggplot2)
library(dplyr)
ui <- fluidPage(
titlePanel("Visualizing Pitcher Statistics"),
sidebarLayout(
sidebarPanel(
helpText("Data from Baseball Prospectus"),
helpText("by Julien Assouline"),
sliderInput("yearinput", "YEAR",
min = 1970, max = 2016, value = c(2000, 2016),
animate = TRUE),
selectInput("xcol", "X Axis",
choices = c("YEAR","AGE","NAME","G","GS","PITCHES","IP","IP.Start","IP.Relief","W","L","SV","BS","PA","AB","R","ER","H","X1B","X2B","X3B","HR","TB","BB","UBB","IBB","SO","HBP","SF","SH","PPF","FIP","cFIP","ERA","DRA","PWARP","TEAMS","ROOKIE","League")),
selectInput("ycol", "y Axis",
choices = c("PWARP","YEAR","NAME","AGE","G","GS","PITCHES","IP","IP.Start","IP.Relief","W","L","SV","BS","PA","AB","R","ER","H","X1B","X2B","X3B","HR","TB","BB","UBB","IBB","SO","HBP","SF","SH","PPF","FIP","cFIP","ERA","DRA","TEAMS","ROOKIE","League")),
checkboxInput(inputId = "smoother",
label = "show smoother",
value = FALSE),
downloadButton("downloadPNG", "Download as a PNG file")
),
mainPanel(
tabsetPanel(
tabPanel("Scatterplot", plotOutput("plot1"),
verbatimTextOutput("descriptionTab1"), value = "Tab1"),
tabPanel("Line Chart", plotOutput("plot2"),
verbatimTextOutput("descriptionTab2"), value = "Tab2"),
id = "theTabs"
))
)
)
server:
server <- function(input, output){
ScatterPlot <- reactive({
BP_Pitcher_1967_2016 <- read.csv("/Users/julienassouline/BP Pitcher 1967 2016.csv", header=TRUE, check.names = FALSE)
Filtered1 <- BP_Pitcher_1967_2016 %>%
filter(
YEAR >= input$yearinput[1],
YEAR <= input$yearinput[2]
)
p <- ggplot() +
geom_point(data = Filtered1, aes_string(x = input$xcol, y = input$ycol)) +
Julien_theme()
if(input$smoother)
p <- p + geom_smooth(data = Filtered1, aes_string(x = input$xcol, y = input$ycol), colour = "red")
print(p)
})
output$plot1 <- renderPlot({
print(ScatterPlot())
output$downloadPNG <- downloadHandler(
filename = "Graph.png",
content = function(file){
png(file)
print(ScatterPlot())
dev.off()
})
})
linechart <- reactive({
BP_Pitcher_1967_2016_trends <- read.csv("/Users/julienassouline/BP_Pitcher_1967_2016_trends.csv", header=TRUE, check.names = FALSE)
Filtered2 <- BP_Pitcher_1967_2016_trends %>%
filter(
YEAR >= input$yearinput[1],
YEAR <= input$yearinput[2]
)
d <- ggplot() +
geom_line(data = Filtered2, aes_string(x = input$xcol, y = input$ycol), colour = "blue", size = 1) +
Julien_theme()
print(d)
}
)
output$plot2 <- renderPlot({
print(linechart())
output$downloadPNG <- downloadHandler(
filename = "Graph.png",
content = function(file){
png(file)
print(linechart())
dev.off()
})
})
}
shinyApp(ui = ui, server = server)
When I run the app it works just fine. But, when I try to publish it, it first tells me "line 42 Paths should be to files within the project directory" "line 70 Paths should be to files within the project directory"
If I try to publish it any way I get this error:
"error cannot open connection" https://julien1993.shinyapps.io/Shiny-App-3/
I have tried creating a new R document with the csv files passed to the data frames. I also have my R document saved in a file called Shiny-App-3, where I also tried to add the csv files. That doesn't work.
I am also aware, of this question. Data object not found when deploying shiny app. That said if I place the csv files code outside the reactive function, and at the begging of my document, it still doesn't work.
If I don't include BP_Pitcher_1967_2016 <- read.csv("/Users/julienassouline/BP Pitcher 1967 2016.csv"
line of code, or this BP_Pitcher_1967_2016_trends <- read.csv("/Users/julienassouline/BP_Pitcher_1967_2016_trends.csv", header=TRUE, check.names = FALSE)
then I get the error object 'BP_Pitcher_1967_2016' not found
and object 'BP_Pitcher_1967_2016_trends' not found
.
The method described here also doesn't work, for what it's worth: Shiny/R error: Paths should be to files within the project directory
Would anybody know what the problem is? All help is appreciated.