2015-04-30 10 views
6

Pracuję nad moim pierwszym błyszczące aplikacji i używam do problemu gdzie dane, który jest używany do renderowania moją tabelę danych nie jest odebrany przez shinyapps.io.danych nie znaleziono obiektu podczas wdrażania błyszczące APP

Aplikacja działa poprawnie w mojej konsoli, ale kiedy ją wdrożę, otwiera się aplikacja w przeglądarce z błędem: nie znaleziono obiektu "Pitchers", gdzie "Pitchers" jest jednym z moich obiektów danych.

Znalazłem one suggestion, który powiedział, że umieści twoje dane w folderze w folderze aplikacji, ale to wciąż nie działa.

Tu jest mój bieżący kod server.R:

shinyServer(function(input, output) { 

    Pitchers <- read.csv("data/Pitchers_Edge.csv", header=TRUE, check.names = FALSE) 
    Batters <- read.csv("data/Batters_Edge.csv", header=TRUE, check.names = FALSE) 

    output$table1 <- renderDataTable({ 

    if (input$Year != "All"){ 
     Pitchers <- Pitchers[Pitchers$Year == input$Year,] 
    } 
    Pitchers 
    }) 

    output$table2 <- renderDataTable({ 

    if (input$Year != "All"){ 
     Batters <- Batters[Batters$Year == input$Year,] 
    } 
    Batters 
    }) 

}) 

A oto kod ui.R:

shinyUI(fluidPage(
    titlePanel('Edge%: 2010-Present'), 
    fluidRow(
     column(12, 

        p("Provides current and historical data on the percentage of pitches thrown to different parts of the strike zone by pitchers and to batters"), 
        p("Created and maintained by Bill Petti", 
         a("(@BillPetti)", href = "https://twitter.com/billpetti")), 
        p("Data last updated",Sys.time())) 
    ), 
    fluidRow(
    column(5, 
      selectInput("Year", 
         "Year:", 
         c("All", 
         unique(as.character(Pitchers$Year))))) 
    ), 
    mainPanel(
     tabsetPanel(
     tabPanel("Pitchers", dataTableOutput(outputId = 'table1')), 
     tabPanel("Batters", dataTableOutput(outputId = 'table2')), 
     tabPanel("About", 
      br(), h1("About Edge%"), 
      br(), p("A few years ago, Jeff Zimmerman and I created a metric to represent how often a pitcher threw to the edges of the strike zone compared to the heart of the strike zone. The result was Edge%. The metric has evolved to include separate metrics for different edges (upper, lower, etc.). In the image below, the brown shaded areas represent the horizontal edges of the strike zone, the blue the top, and the green the bottom edges. You will notice the horizontal edges differ by batter handedness, given how umpires actually call balls and strikes."), 
      br(), img(src = "edge_image.png", height = 350, width = 700)), 
      br(), p("Edge% is useful in a number of contexts. For example, we know that as pitchers age they lose velocity and therefore need to avoid throwing to the heart of the plate to be successful. Edge% provides a quick look at who is adjusting to lower velocity and who isn't. It can also be used to see how pitchers are adjusting to hitters as they age (i.e. as hitters improve, pitchers may avoid the heart of the plate more, or as hitters decline they may begin challenge them more."), 
      br(), p("For more information on Edge%, check out these articles:", 
      br(), br(), a("Introduction to Edge%", href = "http://www.fangraphs.com/blogs/the-difference-pitching-on-the-edge-makes/"), 
      br(), br(), a("Collection of Articles Using and Expanding on Edge%", href = "http://www.fangraphs.com/blogs/category/edge/"), 
      br(), br(), a("Most Recent Version", href = "http://www.hardballtimes.com/expanding-the-edges-of-the-strike-zone/") 
                                                                                                                                                                            ) 
       ) 
) 
) 
) 

mam rozmieszczanie z systemem Windows.

Doceniam wszelkie sugestie!

Aktualizacja

Wziąłem porady Colina i zaktualizowane mojego kodu, ale jestem nadal pracuje w tej samej kwestii.

Oto co moja aplikacja powinna wyglądać po wdrożeniu:

http://i.stack.imgur.com/idmvC.jpg

A oto co się dzieje, gdy publikują i widok, lokalnie lub w internecie:

http://i.stack.imgur.com/ikBrD.jpg

It nie chodzi tylko o to, że obiektowi brakuje, ale widzę resztę aplikacji. Cała aplikacja po prostu znika.

Tu jest mój zaktualizowany kod:

library(shiny) 

shinyServer(function(input, output) { 

    Pitchers <- reactive({read.csv("data/Pitchers_Edge.csv", header=TRUE, check.names = FALSE)}) 
    Batters <- reactive({read.csv("data/Batters_Edge.csv", header=TRUE, check.names = FALSE)}) 

    output$table1 <- renderDataTable({ 
    Pitchers <- Pitchers() 
    if (input$Year != "All"){ 
     Pitchers <- Pitchers[Pitchers$Year == input$Year,] 
    } 
    subset(Pitchers, Pitchers$'# of total pitches'>= input$pitch_total) 
    }) 

    output$table2 <- renderDataTable({ 
    Batters <- Batters() 
    if (input$Year != "All"){ 
     Batters <- Batters[Batters$Year == input$Year,] 
    } 
    subset(Batters, Batters$'# of total pitches'>= input$pitch_total) 
    }) 

}) 

shinyUI(fluidPage(
    titlePanel('Edge%: 2010-Present'), 
    fluidRow(
    column(12, 
      p("Provides current and historical data on the percentage of pitches thrown to different parts of the strike zone by pitchers and to batters"), 
      p("Created and maintained by Bill Petti", 
      a("(@BillPetti)", href = "https://twitter.com/billpetti")), 
      p("Data last updated",Sys.time())) 
), 
    sidebarLayout(
    sidebarPanel(selectInput("Year", 
            "Year:", 
            c("All", 
             unique(as.character(Pitchers$Year)))), 
       numericInput("pitch_total", 
          label = "Minimum # of Pitches:", 
          value = 300) 
) 
    , 
    mainPanel(
    tabsetPanel(
     tabPanel("Pitchers", dataTableOutput(outputId = 'table1')), 
     tabPanel("Batters", dataTableOutput(outputId = 'table2')), 
     tabPanel("About", 
       br(), h1("About Edge%"), 
       br(), p("A few years ago, Jeff Zimmerman and I created a metric to represent how often a pitcher threw to the edges of the strike zone compared to the heart of the strike zone. The result was Edge%. The metric has evolved to include separate metrics for different edges (upper, lower, etc.). In the image below, the brown shaded areas represent the horizontal edges of the strike zone, the blue the top, and the green the bottom edges. You will notice the horizontal edges differ by batter handedness, given how umpires actually call balls and strikes."), 
       br(), img(src = "edge_image.png", height = 350, width = 700), 
     br(), p("Edge% is useful in a number of contexts. For example, we know that as pitchers age they lose velocity and therefore need to avoid throwing to the heart of the plate to be successful. Edge% provides a quick look at who is adjusting to lower velocity and who isn't. It can also be used to see how pitchers are adjusting to hitters as they age (i.e. as hitters improve, pitchers may avoid the heart of the plate more, or as hitters decline they may begin challenge them more."), 
     br(), p("For more information on Edge%, check out these articles:"), 
       br(), a("Introduction to Edge%", href = "http://www.fangraphs.com/blogs/the-difference-pitching-on-the-edge-makes/"), 
       br(), br(), a("Collection of Articles Using and Expanding on Edge%", href = "http://www.fangraphs.com/blogs/category/edge/"), 
       br(), br(), a("Most Recent Version", href = "http://www.hardballtimes.com/expanding-the-edges-of-the-strike-zone/") 
    ) 
    ))))) 

Odpowiedz

6

Och! Myślę, że nie ładujesz pliku miotaczy jako części skryptu ui.R. Więc kiedy definiujesz rok wprowadzenia, nie możesz znaleźć Pitchers $ year. Czy możesz spróbować odczytać plik miotaczy w skrypcie interfejsu użytkownika powyżej połączenia shinyUI()?

Niektóre rzeczy o danych injest w błyszczące: Jeśli dane nie będą regularnie zmieniać, nie trzeba swoje dane przetworzyć być reaktywne. Wystarczy umieścić go na samym początku pliku serwera przed wywołaniem shinyServer(). Ta część kodu zostaje uruchomiona tylko raz, gdy wdrażasz aplikację, więc jest to dobre miejsce do wykonywania połączeń, danych lub przetwarzania danych, które w żaden sposób nie zależą od użytkownika. Możesz po prostu użyć read.csv() w taki sam sposób, jak w zwykłym R, czasami dobrze jest zapisać binay z ramką danych, ponieważ read.csv może być nieco powolny.

Jeśli ma się zmienić (jak zaktualizowany plik CSV zostanie umieszczony w pliku regularnie), a następnie umieścić połączenie read.csv() pod numerem shinyServer(), ale znowu nie musi być reaktywny.

Nadzieję, że pomaga!

+1

Pewnie tak! Dzięki, to wydawało się rozwiązać problem. Mój ostatni kod to [tutaj] (https://github.com/BillPetti/Scheduling-Shiny-App), jeśli ktoś ma na to oko. – BillPetti

1

Gdy pojawi się wewnątrz funkcji renderDataTable, nie rozpoznaje co Dzbany dlatego, że została zdefiniowana poza funkcją. Jeśli jednak ustawisz Pitchers jako element reaktywny, możesz go wywołać w ramach funkcji. Tak ustawić zmienną, a następnie wywołać ją jako funkcję wewnątrz funkcji renderowania.

Pitchers<- reactive({read.csv("Your Stuff")}) 

output$table1 <- renderDataTable(
Pitch<-Pitchers() 

"Then call all your if statements and such on the function using Pitch" 
) 

Mam nadzieję, że pomoże!

+0

Dzięki, Colin! Wciąż mam problem - zaktualizowałem swój kod i podałem linki do zdjęć z tego, co się dzieje. Wydaje się, że może to być większy problem, ponieważ aplikacja wydaje się dosłownie znikać po wdrożeniu w sieci. – BillPetti

0

Niedozwolone połączenie z poprzednią odpowiedzią:

Zgadzam się, że problem polega na tym, że obiekt "Pitchers" musi być zdefiniowany zarówno na shinyServer, jak i na shinyUI. Stworzenie trzeciego pliku o nazwie "global.R" może być najlepszym sposobem rozwiązania tego problemu, ponieważ w ten sposób wystarczy raz przeczytać bazę danych (która jest szybsza i ładniejsza dla darmowego serwera shinyapps.io). Więcej informacji na temat tworzenia zmiennych o zasięgu globalnym można znaleźć pod numerem https://shiny.rstudio.com/articles/scoping.html.

Powiązane problemy