user46543
user46543

Reputation: 1053

Deploying Shiny apps with local dataset

I tried to deploy my Shiny apps to xxx.shinyapps.io, but the problem is I use own dataset. I set my dataset to my directory, but when I try to deploy it I got error:

Listening on http://127.0.0.1:45220 Loading required package: DBIError in setwd("C:/Users/xxx/Dropbox/shiny/archive/db") : cannot change working directory

Upvotes: 2

Views: 5529

Answers (4)

Navin Manaswi
Navin Manaswi

Reputation: 992

There are two ways

  1. Open a ".R"(navin.R e.g.) file in the app directory( where ui.r and server.R is placed) where you make the R object which contains the data (For example: dataS <- read.csv("XX.csv"); dataT <- read.csv("YY.csv"))

    and then in server.R , write the code initially: source(navin.R) And use dataS, dataT objects as usual.

  2. Place XX.csv and YY..csv in the same directory ( or any directory but then give the "relative path" ) and do everything as usual

For example : I used local data to make shiny Apps https://manaswink.shinyapps.io/TelecomTower/

Upvotes: 1

Krishnesh Pujari
Krishnesh Pujari

Reputation: 1

Adding to the comments provided by Paul

  1. Insert the relative path to both ui.R and server.R
  2. No need to pre-load the data file, it loads successfully along with runApp()
  3. Finally, you can directly publish it to the shinyapps.io

Sample code:

For -> ui.R - where 'county.csv is local dataset'
county1<-read.csv("Data/county.csv")
library(shiny)
shinyUI(pageWithSidebar(..
..........
.......

Similarly,

For -> server.R
county1<-read.csv("Data/county.csv")
shinyServer(function(input, output, session) {....
......
......

Upvotes: 0

Navin Manaswi
Navin Manaswi

Reputation: 992

In server.R , have this code at the top

source("datarep.R)

Make a new .R file "datarep.R " in the same directory. That file has just one code

data <- read.csv("data.csv")

Upvotes: 2

John Paul
John Paul

Reputation: 12664

Put your dataset in a subdirectory of your shiny app directory (and change you code accordingly). Be sure to make the path to the data a relative path (not an absolute path - this generates a warning). This has worked well for me.

Upvotes: 9

Related Questions