Data object not found when deploying shiny app

前端 未结 3 388
一生所求
一生所求 2021-01-05 04:27

I am working on my first shiny app and am running into an issue where the data that is used to render my data table is not being picked up by shinyapps.io.

The app

相关标签:
3条回答
  • 2021-01-05 05:02

    Once you get inside the renderDataTable function, it doesn't recognize what Pitchers is because it was defined outside the function. However, if you set Pitchers to be a reactive element, it can be called within the function. So would set the variable and then call it as a function inside the render function.

    Pitchers<- reactive({read.csv("Your Stuff")})
    
    output$table1 <- renderDataTable(
    Pitch<-Pitchers()
    
    "Then call all your if statements and such on the function using Pitch"
    )
    

    Hope that helps!

    0 讨论(0)
  • 2021-01-05 05:08

    Oh! I think it's that you're not loading the pitchers file as part of the ui.R script. So when you're defining the year input it's not able to find Pitchers$year. Can you try reading the pitchers file in the ui script above the shinyUI() call?

    Some stuff about data injest in shiny: If your data's not going to change regularly, you don't need your data-ingest to be reactive. Just put it at the very beginning of the server file before the shinyServer() call. That part of the code gets run just once, when you deploy the app so it's a good place to do any library() calls, data injest, or pre-processing stuff that doesn't depend upon the user in any way. You can just use read.csv() in the same was as you would in regular R, it's also sometimes good to save a binay of the dataframe because read.csv can be a bit slow.

    If it is going to change (like an updated csv is going to be put in the file regularly) then put the read.csv() call below the shinyServer() call but again shouldn't need to be reactive.

    Hope that helps!

    0 讨论(0)
  • 2021-01-05 05:09

    Piggybacking on a previous answer:

    I agree that the problem is that the object "Pitchers" needs to be defined in both shinyServer and shinyUI. Creating a third file called "global.R" may be the best way to solve this problem, since that way you only need to read the database one time (which is faster and nicer to the free shinyapps.io server). See https://shiny.rstudio.com/articles/scoping.html for more information about creating variables with a global scope.

    0 讨论(0)
提交回复
热议问题