为什么我的Shiny应用程序没有发布

Jul*_*ien 3 r shiny

我在尝试发布我的Shiny应用时遇到了问题.

这是我发布的应用程序的代码:

用户界面:

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"
      ))
  )
)
Run Code Online (Sandbox Code Playgroud)

服务器:

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) 
Run Code Online (Sandbox Code Playgroud)

当我运行应用程序时它工作得很好.但是,当我尝试发布它时,它首先告诉我"第42行路径应该是项目目录中的文件""第70行路径应该是项目目录中的文件"

如果我尝试以任何方式发布它,我会收到此错误:

"错误无法打开连接" https://julien1993.shinyapps.io/Shiny-App-3/

我尝试使用传递给数据框的csv文件创建一个新的R文档.我还将我的R文档保存在名为Shiny-App-3的文件中,我还尝试添加csv文件.这不起作用.

我也知道这个问题.部署闪亮的应用程序时找不到数据对象.这就是说,如果我将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 foundobject 'BP_Pitcher_1967_2016_trends' not found.

这里描述的方法也不起作用,因为它的价值: Shiny/R错误:路径应该是项目目录中的文件

有谁知道问题是什么?所有帮助表示赞赏.

Mik*_*ise 5

错误消息只是告诉您不能使用绝对文件路径.尝试将两个数据文件(BP Pitcher 1967 2016.csvBP_Pitcher_1967_2016_trends.csv)放入与闪亮程序相同的目录/文件夹中,并从代码中的名称中删除路径.

所以第24行看起来像:

BP_Pitcher_1967_2016 <- read.csv("BP Pitcher 1967 2016.csv",header=TRUE, check.names=FALSE)
Run Code Online (Sandbox Code Playgroud)

和第70行看起来像:

BP_Pitcher_1967_2016_trends <- read.csv("BP_Pitcher_1967_2016_trends.csv", header=TRUE,check.names=FALSE)
Run Code Online (Sandbox Code Playgroud)

测试一下.如果你做得对,它应该工作.然后尝试发布.它应该也可以正常工作,除非还有另一个我们还没有看到的错误.