namkyodai / 2022-UrbanComputation-SUTD

Notes, reading materials, data and codes for Spring Semester course named "Urban Data & Methods II: Computational Urban Analysis" at SUTD Singapore.
MIT License
4 stars 7 forks source link

RStudio Cloud #4

Open inesltt opened 2 years ago

inesltt commented 2 years ago

Hi Nam,

I'm facing some issues uploading files into my cloud directory; I receive an error message saying "Unexpected response from server". I've attempted to consult prof google and found tips to use either the wget or curl function, but alas, I am facing issues using them as well. Would appreciate your helP!!

Screenshot 2022-04-02 at 8 57 31 PM
slouisephuah commented 2 years ago

I managed to load the data from PostgreSQL using this code:

install.packages(c('DBI', 'RPostgres')) #installing relevant packages if you haven't already

library(DBI) #calling the necessary packages
library(RPostgres)

con <- DBI::dbConnect(
  RPostgres::Postgres(),
  dbname = 'assignment 1', #input name of DB where the file was uploaded
  host = 'localhost',
  port = 5432,
  user = 'postgres', #input your username (it's probably postgres)
  password = 'Helopanda16!') #lol pls don't hack into my stuff

dbListTables(con) #shows all the different tables which were uploaded in DB
propertylisting <- dbReadTable(con, "propertylistings") #reads the specific table in the DB we want, and converts it into a data frame

Some pretty helpful documentation I referred to:

let me know if this works!!

slouisephuah commented 2 years ago

Another easier (in my opinion haha) method is to export the necessary files into a .csv format, then loading them into R!

To export the file (which our group already loaded into a database in DBeaver last week), right click the table > Export > select "CSV" as the Export target > Click next for everything (use the standard settings) > Click finish.

Then upload the .csv file into your working directory in R Studio cloud (in the bottom right box, click upload > Choose file to upload). And then input this code to read in the .csv file:

proplisting <- read.csv("propertylistings_202204011043.csv") #you can name the file sth other than proplisting of course

Screen Shot 2022-04-03 at 12 06 42 PM

y

inesltt commented 2 years ago

Thanks Shannon, but the second method doesn't work as well :):):) ;((((((

namkyodai commented 2 years ago

I managed to load the data from PostgreSQL using this code:

install.packages(c('DBI', 'RPostgres')) #installing relevant packages if you haven't already

library(DBI) #calling the necessary packages
library(RPostgres)

con <- DBI::dbConnect(
  RPostgres::Postgres(),
  dbname = 'assignment 1', #input name of DB where the file was uploaded
  host = 'localhost',
  port = 5432,
  user = 'postgres', #input your username (it's probably postgres)
  password = 'Helopanda16!') #lol pls don't hack into my stuff

dbListTables(con) #shows all the different tables which were uploaded in DB
propertylisting <- dbReadTable(con, "propertylistings") #reads the specific table in the DB we want, and converts it into a data frame

Some pretty helpful documentation I referred to:

let me know if this works!!

@inesltt sorry for my late reply. Best is that you can allow me to have a close look into the problem --> I am OK for 30 minutes one-to-one discussion if you still face the issue.

Note that in Rcloud, sometimes the issue is with the server.