我在试图发布我的Shiny应用程序时遇到问题。为什么不是我的Shiny应用程序发布
这里是我发布的应用程序的代码:
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 <- 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)
当我运行的应用程序它工作得很好。但是,当我尝试发布它时,它首先告诉我“第42行路径应该是项目目录中的文件” “第70行路径应该是项目目录中的文件”
如果我尝试发布它什么办法,我得到这个错误:
“错误无法打开连接” https://julien1993.shinyapps.io/Shiny-App-3/
我试图创造与传递到数据帧的CSV文件新的R文件。我还将我的R文档保存在名为Shiny-App-3的文件中,我也尝试添加csv文件。这是行不通的。
我也知道,这个问题。 Data object not found when deploying shiny app。这就是说,如果我把csv文件代码放在反应函数之外,并且在我的文档的乞求下,它仍然不起作用。
如果我不包括BP_Pitcher_1967_2016 <- read.csv("/Users/julienassouline/BP Pitcher 1967 2016.csv"
行代码或这BP_Pitcher_1967_2016_trends <- read.csv("/Users/julienassouline/BP_Pitcher_1967_2016_trends.csv", header=TRUE, check.names = FALSE)
那么我得到错误object 'BP_Pitcher_1967_2016' not found
和object 'BP_Pitcher_1967_2016_trends' not found
。
这里也描述不工作,为它的价值的方法: Shiny/R error: Paths should be to files within the project directory
会有人知道问题是什么? 所有帮助表示赞赏。
非常感谢!当我将'BP_Pitcher_1967_2016 < - read.csv(“/ Users/julienassouline/Shiny-App-3/BP Pitcher 1967 2016.csv”,header = TRUE,check.names = FALSE)添加到我的目录中时, 。 – Julien
不客气。活到老,学到老 :) –