Load in results of random forest

Hello all,

I have a shiny app that relies on the results given of a random forest from the caret package that is used in a predict() function. The results of creating the random forest would take far too long to run every time the app opens. I have saved the results of the random forest to an .Rds file, but I am not sure how to read the .Rds file in to start the application. Obviously, I would need it saved in Dropbox or something similar (not on my machine, stored localy), but whenever I try to load in from dropbox using the rdrop2 function drop_download(), it will not allow me to do so, it throws error and the session times out. If anyone can think of an easier way to load in the .Rds file, or if I could store the random forest in another type of file, I would greatly appreciate an feedback.


Are you familiar with the golem package? It is a framework for building shiny apps, which lets you build an app as though it was an R package. It will serve your purpose because it lets you embed data directly into your Shiny app (like an R package).

Alternatively, you may want to share the error your get when you try to use the rdrop2 function so that people who know about it can help.

I had not previously heard of the golem package, but will definately look into it. Thanks for pointing it out! When I try to load in my model from Dropbox (saved as an .Rds file) I first tried. model=load(url("[mydropboxurl]?dl=1"])) but I got the following error: the input does not start with a magic number compatible with loading from a connection I then tried using the drop_download function in the app. Something like this: token=drop_auth() drop_download(path='model3.rds', overwrite=TRUE, dtoken=token)but the app would not load in, I always got a timeout error. If you could help with either of these errors, I'd appreciate it!

Unfortunately, I do not know much about the r2drop package, but there are definitely many options to include data in your Shiny app. I talked about the golem package, but you could also look into using Google Drive instead of Dropbox to see if it likes you better :smiley:

Thanks so much for all of your help. I eventually figured it out. What I needed to do was do model=readRDS(url("[mydropboxurl]?dl=1"])) instead of using load.

1 Like

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.