Mithilesh Kumar
Mithilesh Kumar

Reputation: 263

Embedding multiple shiny apps in single Rmarkdown file using "shinyAppDir" function

I have created several shiny apps to embed in single Rmarkdown file. I am using Amazon ec2 Ubuntu machine for hosting my shiny apps and rstudio. All the working apps are at /srv/shiny-server.

To do this, I create another folder for Rmarkdown single file in /srv/shiny-server. The individual chunks are running but Run Document commands is giving an error:

ERROR: cannot open the connection

I am using following R markdown code:

### App 1 goes here
    ```{r, echo=FALSE}
library(shiny)
shinyAppDir(
  "/srv/shiny-server/App1",
  options=list(
    width="100%", height=550
  )
)
```
### App 2 goes here
    ```{r, echo=FALSE}
library(shiny)
shinyAppDir(
  "/srv/shiny-server/App2",
  options=list(
    width="100%", height=550
  )
)
```
## Likewise ...

Upvotes: 4

Views: 1388

Answers (1)

Erin Shellman
Erin Shellman

Reputation: 3713

Not sure this will answer your question, but I encountered this problem and here's what I found. I'm running a shiny server on an Ubuntu EC2 instance. Also, I didn't create shiny apps the same way you did, instead I embedded interactive visualizations in R Markdown using ggvis and the shiny runtime like so:

---
date: "`r format(Sys.time(), '%d %B, %Y')`"
output:
  html_document:
    theme: readable
    toc: yes
    toc_depth: 3
runtime: shiny
---

Here are the two things that caused my problem:

  1. Wrong paths to sourced code or data. You can provide absolute paths or paths relative to where your Rmd is located.
  2. Using cache = TRUE in code chunks.

You can't cache things and when you do it causes the "cannot open the connection" error.

Upvotes: 1

Related Questions