简体   繁体   中英

Load a csv file in R and share in all sessions?

I have a shiny application that uses a csv file to generate different figures. I upload my application in my personal linux server using shiny-server. I use this structure for my application

  • global.R
  • ui.R
  • server.R

Inside my global.R file I have this line, which help me to load and read my csv file

df <- read_csv("../Desktop/covid_2021-02-15.csv")

But my application is very slow, I read that objects in the global.R script, are read only one time and are share in all sessions.

Is there other way to load this data frame to have a more efficient application?

In addition to the comments from Gregor and HubertL:

To load large CSV files can slow down. I had the same issue and changed to r binary file (rds) with saveRDS() and readRDS() . As a first step you can try rds file and see if the issue is solved. To check whether there is a performance difference you can use system.time(). Returns the time taken to evaluate any R expression.

In your case:

df <- read_csv("../Desktop/covid_2021-02-15.csv")
# Save an object to a file
saveRDS(df, file = "my_data.rds")
# Restore the object
readRDS(file = "my_data.rds")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM