Skip to content

Instantly share code, notes, and snippets.

@ijlyttle
Created August 1, 2014 13:26
Show Gist options
  • Select an option

  • Save ijlyttle/fe31fa61a97d981ad7f4 to your computer and use it in GitHub Desktop.

Select an option

Save ijlyttle/fe31fa61a97d981ad7f4 to your computer and use it in GitHub Desktop.
subApp cannot find data directory
---
title: "SubApp path to data"
author: "Ian Lyttle"
runtime: shiny
output:
html_document:
theme: united
---
This is a case where a subApp behaves differently from an app.
To reproduce this, you will have to create a directory for the app, then write out the app and the data.
Define/create our directories:
```{r directories}
app_path <- file.path("app")
dir.create(app_path) # warning: may generate warning
data_path <- file.path(app_path, "data")
dir.create(data_path) # same warning
```
Let's start with the data:
```{r csv_create}
write.csv(
data.frame(x = seq(1, 5), y = seq(1, 5)),
file.path(data_path, "linear.csv"),
row.names = FALSE
)
```
Let's write out a short app.
```{r}
txt_ui <- "
library(shiny)
library(ggvis)
shinyUI(fluidPage(
fluidRow(
column(3, wellPanel()),
column(6, ggvisOutput('gg_linear')),
column(3, wellPanel())
)
))
"
txt_server <- "
library(shiny)
library(ggvis)
shinyServer(function(input, output, session) {
data <- read.csv(
file.path('data', 'linear.csv'),
header = TRUE
)
data %>%
ggvis(x = ~x, y = ~y) %>%
layer_points() %>%
bind_shiny('gg_linear')
})
"
cat(txt_ui, file = file.path(app_path, "ui.R"))
cat(txt_server, file = file.path(app_path, "server.R"))
```
Let's run this app within this page:
```{r}
shinyAppDir(app_path)
```
### What I find
Running this document using the "Run Document" button, then rendering in the browser, the subApp cannot find the data directory.
Running the app from the command line, shiny finds everything OK.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment