I would like to download a google docs spreadsheet using R and then import the spreadsheet as a csv file in a small shiny server app.
How could I do that?
Try the new googlesheets package, which is an R API for Google Sheets:
https://github.com/jennybc/googlesheets
This snippet will install the package, copy a Sheet to your Google Drive, register it for access, and import data from one tab or worksheet into a local data.frame:
devtools::install_github("jennybc/googlesheets")
gap_key <- "1HT5B8SgkKqHdqHJmn5xiuaC04Ngb7dG9Tv94004vezA"
copy_ss(key = gap_key, to = "Gapminder")
gap <- register_ss("Gapminder")
oceania_csv <- get_via_csv(gap, ws = "Oceania")
As for integration with Shiny, see the shinyga package which recently incorporated support for googlesheets:
https://github.com/MarkEdmondson1234/shinyga
You can use RGoogle Docs package to access the Google Docs content. Other option worth consider is the RGoogle Data package that provides access to Google services.
Related
I am trying to use huggingface multi_nli to train a text multi-classification ai in google cloud. I want to call the ai from a firebase web app eventually. But when I try this code in colab:
!pip install datasets
from datasets import load_dataset
# Load only train set
dataset = load_dataset(path="multi_nli", split="train")
It says its saved in /root/.cache/huggingface/datasets/multi_nli/default/0.0.0/591f72e... but I can't find the file, only a variable version, so I can't move it to google cloud. What is missing for the download to work? Is there some other workaround get it to go to google cloud?
It is easy to do with the method Dataset.save_to_disk and the help of the package gcsfs. You will need first to install gcsfs:
pip install gcsfs
And then you can use the methods Dataset.save_to_disk and Dataset.load_from_disk to save and load the dataset from Google Cloud Storage bucket. To save it:
from datasets import load_dataset
from gcsfs import GCSFileSystem
fs = GCSFileSystem()
dataset = load_dataset(path="multi_nli", split="train")
dataset.save_to_disk("gs://YOUR_BUCKET_NAME_HERE/multi_nli/train", fs=fs)
This will create a directory in the Google Cloud Storage bucket BUCKET_NAME_HERE with the content of the dataset. Then to load it back you only need to execute the following:
from datasets import Dataset
from gcsfs import GCSFileSystem
fs = GCSFileSystem()
dataset = Dataset.load_from_disk("gs://YOUR_BUCKET_NAME_HERE/multi_nli/train", fs=fs)
For more information, please refer to:
Datasets - Cloud Storage
gcsfs
I have a lot of googlesheets that i write in and out from using R. We are merging our sheets into Office online(365).
How can i connect to the online microsoft services (365) from R, especially Excel.
I currently use library(googlesheets) to connect via R.
I will also in instances write some of the current googlesheet data out to the Shiny server using R. I'm looking for some advice and can this be done.
Thanks
You can use the AzureGraph R package by Microsoft (documentation) to get a token via your active directory. Then use the Graph API (documentation) with the call_graph_url function from AzureGraph.
I had issues downloading via the API call, so I used the httr GET function and readxl package once I was able to find the graph download URL:
GET(item[["#microsoft.graph.downloadUrl"]], write_disk(tf <- tempfile(fileext = ".xlsx")))
df <- read_excel(tf)
Per 2022, there is a new (official) package in play that will suit your needs:
https://github.com/Azure/Microsoft365R
How to load CSV files in google colab for R?
For python, there are many answers but can someone guide how file can be imported in R for google colab.
Assuming you mean "get a CSV file from my local system into the Colaboratory Environment" and not just importing it from inside the Colab file paths as per Korakot's suggestion, since your question wasn't very clear, I think you have two main options:
1. Upload a file directly through the shortcut in the side menu thingy.
Just click the icon there and upload your file to drive. Then, you can run normal r import functions by following the internal path like korakot put in this answer.
2. Connect your google drive
Assuming you're using a notebook like the one created by Thong Nguyen, you can use a python call to mount your own google drive, like this one:
cat(system('python3 -c "from google.colab import drive\ndrive.mount()"', intern=TRUE), sep='\n', wait=TRUE)
... which will initiate the login process to Google Drive and will allow you to access your files from google drive as if they were folders in colab. There's more info about this process here.
In case you use the Colab with R as runtime type (and Python code would not work therefore), you could also simply upload the file as MAIAkoVSky suggested in step 1 and then import it with
data <- read.csv('/content/your-file-name-here.csv')
The filepath can also be accessed by right clicking on the file in the interface.
Please be aware that the files will disappear once you disconnected from Colab. You would need to upload them again for the next session.
You can call the read.csv function like
data = read.csv('sample_data/mnist_test.csv')
I'm trying to import a GTFS realtime data file into R using the ProtoBuf package, but can't get it to work. This is what I've tried, but I think it's way off track.
library(RProtoBuf)
setwd("c:\\temp\\")
proto <- readProtoFiles("seq")
The gtfsway package reads the data from the site, like this question, but the authors say the package is outdated.
I have an iPad Pro as my primary computer, and am running R Studio from a cloud server for a class. I am trying to figure out how to import data sets, since my local working directory is on the server. I have been trying to download the package repmis, since I have been reading that that package allows for data set import from Dropbox. However, when I try to download the package, I get "Error:configuration failed for openssl" and a similar one for curl. I tried to install openssl but instead it says I need to install "deb" for ubuntu operating systems, but I can't find that in R Studio in the package database. (And I can't install curl without openssl either) Any suggestions?
If it's a relatively straightforward data set like a CSV, XML, JSON or even an .RData file you can use a Dropbox sharing URL to read it. Here's an example (it's a live URL) for reading in a CSV directly from a shared Dropbox link:
read.csv("https://www.dropbox.com/s/7xg5u0z1gtjcuol/mtcars.csv?dl=1")
The dl=1 won't be the default from a "share this link" copy (it'll probably be dl=0.
urla<- 'https://www.dropbox.com/s/fakecode/xyz.txt?raw=1'
bpdata<-read.table(urla, header=TRUE)
scode<-'https://www.dropbox.com/s/lp6fleehcsb3wi9/protoBP.R?raw=1'
source(scode)
readAndPlotZoomForYear(urla, 2019)
Basically I wanted to source code from a file in Dropbox and to use the read.table() function on a tab delineated data file. I found this could be done by replacing the string after the question mark with raw=1 in the Dropbox file links.