How can a shiny app handle read.csv of an https located csv file the way a local instance can? - r

I have a shinyapps.io application running fine, referencing a number of google sheets (by using publish->csv). This means that I can read.csv(url) those https://... urls both locally and in my shiny app. That's excellent.
However, one of my data partners offered up a csv file at their own https location, and that time the application failed with
"ERROR: cannot open the connection to
'https://www.ncdetect.com/PublicDownload/OverdoseReport.csv'"
I've seem a handful of seemingly related questions elsewhere, though none ended up being helpful.
The (public data) file I can read.csv() with in a shiny app is here, even though it's downloadable and my local instance can handle it just fine: https://www.ncdetect.com/PublicDownload/OverdoseReport.csv .

Related

Unsure where image_write downloads to in shinyapps.io

I'm attempting to make a public shinyapps.io website, and I'm trying to use image_write to create a file into a local directory.
The following code works on my local R studio code:
image_write(im.resized, path = paste0(output_file_directory, file_name), format = "jpg")
When I run the code on the shinyapps.io website, the code runs without error, but I'm not sure where it downloads the file to. I know that the output_file_directory part isn't the issue, so I'm a little lost. Any help would be much appreciated!
On shinyapps.io it is not possibly to store permanently data, due to:
"Shinyapps.io is a popular server for hosting Shiny apps. It is designed to distribute your Shiny app across different servers, which means that if a file is saved during one session on some server, then loading the app again later will probably direct you to a different server where the previously saved file doesn’t exist."
See here:
https://shiny.rstudio.com/articles/persistent-data-storage.html

open a OneDrive file with r

Im tring to create a shiny app that read and online onedrive xlsx file and show some things, but for the moment Im unable to read the onedrive xlsx file, I already explore the Microsoft365R and I can conect to my onedrive and I even can open the fil but... what it does is from r open a tab in chrome with the excel file.
I need the file in the local enviroment of r.. this its beacause the shiny app must be deploy in a web server, that every time the app runs it reads the update the file.
library(Microsfot365R)
odb <- get_business_onedrive()
odb$open_file("lcursos.xlsx")
Also this its a business account, so I also have to put the username and key to acces each file, that its beacause use the simple url doesnt work, it says Error 403 FORBIDEEN.
Any ideas?
Thank you so much!
Use the download_file() method to download the file to your local machine:
odb$download_file("lcursos.xlsx")
You can set the location of the download with the dest argument. Once it's downloaded, open it with the xls reader package of your choice. I suggest either openxlsx or readxl.
Note that if your file is password protected, your options are limited. See this question for possible solutions.

write.csv and read.csv in Shiny App shared on shinyapps.io

I have created an app that I want to share on shinypps.io
Within the code for the I use the functions load, write.csv, and read.csv which read and write files to folders called outputs and data. My app works fine when I run it locally but when I deploy it I get the error:
cannot open compressed file 'data\Catchments.RData', probable reason 'No such file or directory'
I tried using a folder called www to store these but still had error messages. Is there a way to use these functions when sharing an app on shinyapps.io?
There's no possibility of using directories in shinyapp.io. An easy fix is to place an upload button inside the app, perform all the manipulations you need and finally download the result with a download button again. Getting the data from a remote server is also a good option.
As shown in this Article
"Local vs remote storage
Before diving into the different storage methods, one important distinction to understand is local storage vs remote storage.
Local storage means saving a file on the same machine that is running the Shiny application. Functions like write.csv(), write.table(), and saveRDS() implement local storage because they will save a file on the machine running the app. Local storage is generally faster than remote storage, but it should only be used if you always have access to the machine that saves the files.
Remote storage means saving data on another server, usually a reliable hosted server such as Dropbox, Amazon, or a hosted database. One big advantage of using hosted remote storage solutions is that they are much more reliable and can generally be more trusted to keep your data alive and not corrupted.
When going through the different storage type options below, keep in mind that if your Shiny app is hosted on shinyapps.io, you will have to use a remote storage method for the time being. In the meantime, using local storage is only an option if you’re hosting your own Shiny Server. If you want to host your own server, here is a guide that describes in detail how to set up your own Shiny Server."

Shiny server on EC2: URL lists folder content instead of displaying app

[Sorry, newbie here!]
I've just installed R server, shiny server on an ubuntu EC2 instance. I have left the shiny-server.conf intact, except that I added: preserve_logs true;. The sample app was working fine.
I have removed /srv/shiny-server/index.html and /srv/shiny-server/sample-apps.
I have linked my app files from my /home/myapp directory to /srv/shiny-server/myapp. The app files consists of a single apps.R, a footer.html, and a small dataset .Rds, and a www/style.css file.
When I navigate to http://[myip]:3838/ the only thing is the directory listing; the only folder is : myapp. When I click to http://[myip]:3838/myapp/ , I see the directory listing as well. That is, I see the content, and I can download each of them. BUt I see no evidence of the app running. If I click on apps.R, my browser downloads the file.
PS: the app works fine when tested in Rstudio, or deployed on Shinyapps.io
If anyone from the future reads this, I wish you heard the loud headslap when I realized my app single-file should be called app.R, not apps.R (which makes a lot of sense in retrospect).

How to Read a .csv file from url

I have successfully developed a Shiny Application for sentiment analysis. When I deployed the application, it was not working. After going through the code I found that my code is referring to the files(emotions.csv.gz,subjectivity.csv.gz) which are located in my system. That could be the reason why the application is not working because on server its not able to find these particular files. Is there be any method to read these files directly from the url where they are present, so that there will be no system dependencies?

Resources