shinyapp.io doesn´t find my dataframe

Hi there. I am trying to run my first shinyapp.io aplication, but I cannot do it. Mi shinyApp is working on my console, but can´t send it to the web. It says "It doesn´t find the dataframe. I have read the problema people have in the community with that, but I can´t find the solution. I hope someone had the same problem and can help me. Thank you before you try. Rubén.
If it´s worth it, here is my code:

#CODE:

setwd("C:/Users/34617/Desktop/cor13-04-2020")
coronavirus <- read.csv("cor13-04-2020/covid_19_data.csv")

library(dplyr)
coronavirus_resume <- select(coronavirus, ObservationDate, Country.Region, Confirmed, Deaths, Recovered)

coronavirus_total <- coronavirus_resume %>% group_by(Country.Region, ObservationDate) %>% summarise(Confirmed = sum(Confirmed),Deaths = sum(Deaths),Recovered = sum(Recovered))
View(coronavirus_total)

r shiny
#Ui
library(shiny)

ui <- (fluidPage(
titlePanel("Introduction table of COVID-19"),
sidebarLayout(
sidebarPanel(
selectInput("instate", "select a country", choices = coronavirus_total$Country.Region)

    ),
    mainPanel(
        
        tabsetPanel(type="tab",
                    tabPanel("Summary", verbatimTextOutput("summary")),
                    tabPanel("Structure", verbatimTextOutput("str")),
                    tabPanel("Data", dataTableOutput("tab")))
        
        
    )
)

)
)

server
library(DT)

server <- (shinyServer(function(input,output){
output$summary <- renderPrint({
coronavirus_total %>%
filter(.,Country.Region %in% input$instate
) %>% summary()
})

output$str <- renderPrint({
    coronavirus_total %>%
        filter(.,Country.Region %in% input$instate
        ) %>% str()
})


output$tab <- renderDataTable((
    
    coronavirus_total %>%
        filter(.,Country.Region %in% input$instate)
    
))

}))

shinyApp(ui = ui, server = server)

Hi Ruben,

First of all, you should not use setwd in your code in a Shiny app (and it is preferable not to use it in general).

Provided you have uploaded the covid_19_data.csv in the same folder as the app when publishing it to shinyapps.io, you should be able to do.

read.csv("covid_19_data.csv")

If that doesn't work you could perhaps post a picture of the publishing pop-up window to show how the covid_19_data.csv file is uploaded to shinyapps.io. For example:

image

Hi Hlynur. Thank you for replying. I think i am doing what you told me, but I don´t know what happened. This is what I get:




I don´t know how do you do that about "Publish files from---" the two files, I only get the app

If you copy the csv file to the app folder of the app you want to publish you will be prompted to "tick" the csv and publish that also to shinyapps.io. In short, it has to be in the same folder for you to publish it also :slight_smile:

Mmm I put all in the same folder "app", and the code as you told me like this:

image

And it can´t find the csv, as it´s not on the R enviroment I guess...I don´t know if I have to put it inside and how…

In this latest post, is this an error that shows up on your local computer or on shinyapps?

running read.csv("covid_19_data.csv") won't work locally, but it will work on shinyapps.

For the shinyapp publishing the file needs to be in the app folder but that would mean that if you were to run this locally you'd have to run read.csv("app_folder/covid_19_data.csv.

Here's an example app.

#
# My app folder is named temp_app
#

library(shiny)
library(here)
library(readr)
library(ggplot2)
library(dplyr)
library(fs)

# mtcars %>%
#     write_csv(path = here("mtcars.csv"))
# 
# fs::file_copy(path = here("mtcars.csv"),
#               new_path = here("temp_app/mtcars.csv"))

my_mtcars <- read_csv("mtcars.csv")

# Define UI
ui <- fluidPage(

    # Application title
    titlePanel("mtcars as read from a csv"),

    # Sidebar with a slider input
    sidebarLayout(
        sidebarPanel(
            sliderInput("filter_sel",
                        "Filter HP:",
                        min = 0,
                        max = 500,
                        value = c(0, 400),
                        step = 10)
        ),

        # Show a plot
        mainPanel(
           plotOutput("carPlot")
        )
    )
)

# Define server logic
server <- function(input, output) {

    output$carPlot <- renderPlot({
        my_mtcars %>% 
            filter(hp >= input$filter_sel[1],
                   hp <= input$filter_sel[2]) %>% 
            ggplot(aes(x = hp, y = mpg)) + geom_point()
    })
}

# Run the application 
shinyApp(ui = ui, server = server)

I copied the file so it was in two locations to make this easier. This is an app that you can both run locally with this exact code, and it will run on shinyapps without any changes.

My app file is at temp_app/app.R my csv is at temp_app/mtcars.csv on my local computer so they are in the same app folder. So when I go to publish the app, I get the option to publish also the csv file, as you can see here.
image

Here's the link to the app, working on shinyapps: https://hlynur.shinyapps.io/temp_app/

And just to be clear, when I say "app folder", I mean the one folder that contains the app.R file :slight_smile:

Oh yes I get now what you are trying to tell me!. I put the csv "covid_19_data.csv" in the same folder than the "app.R" on my Desktop. Also do the Reading of it on the same window in Rstudio like this:



And it should work as I can see the two files:
image
But when I run it I get the server error. I think it´s the RStudio web, that is not working now...but if there´s something you think I am doing wrong you can tell me, I hear you.


Thank you very much for your help!!!

Rubén.

I've never had that error before, but a 402 error code means "payment required", I'm wondering if during these test runs you've reached the maximum allowed number of apps for your payment (or free) tier. That would simply mean that you'd have to remove some apps from your shinyapps account.

If I were you, I'd go to the shinyapps.io website. Go to the dashboard. Under "Recent applications" click the name of an app you're willing to remove and on that app's site click "Delete" in the upper right corner. At least that's what I'd try :slight_smile:

OMG after doing what you told me for a long time I finally got it!! Thank you very muuuch! I really appreciate your effort in helping me!

Have a nice day.

Rubén.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.