Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedding Shiny app in knitr document

Tags:

r

shiny

I have a shiny app which has a ui.R, server.R and global.R. The app directory (name = dash) contains the folder 'data' in which the dataset resides. Also, this app folder is inside the project's working directory. In global.R I read the data as:

dash <- read.table("data/ntraj1acc.txt", sep=",", header=T)

This app works fine. Now, I am trying to embed it in a ioslides presentation which otherwise works good. The example in External Applications section on rmarkdown website also works perfect in my presentation. But when I replace the path in system.file to my app, I get the error:

No Shiny application exists at the path ""

Here is how I replaced the path:

shinyAppDir(
  system.file("dash", package="shiny"),
  options=list(
    width="100%", height=700
  )
)

After the error, I tried following:

shinyAppDir(
  "C:/Users/durraniu/Documents/Trajectory-one/dash",
  options=list(
    width="100%", height=700
  )
)

But then I got a new error:

object 'dash' not found

Which means that it is not parsing global.R.

How can I fix this problem?

like image 275
umair durrani Avatar asked Oct 14 '14 01:10

umair durrani


People also ask

How do I embed a shiny app in RMarkdown?

There are two ways to do this: Defining the application inline using the shinyApp() function; or. Referring to an external application directory using the shinyAppDir() function.

Can you embed a shiny app on website?

Yes! A shiny app can be put in an iframe in another website from RStudio Connect. In order to put the app in an iframe, it is recommended to add a content URL, because you can move it to another piece of content should the need arise.

What are the two main differences between an R Markdown document and a shiny dashboard?

It generally comes down to the amount of interactivity you need in your app. For a full solution where data is updated and processed in real-time, Shiny is your best option. If you just need a nice format for presentation offline, then RMarkdown can produce some very nice looking formats.


1 Answers

I successfully embeded an application within an interactive shiny document with the following rmarkdown chunk:

```
shinyAppDir("D:/Documents/OneDrive/Notes/R-Explore/shiny/01-ages/",
  options=list(
    width="100%", height=550
  )
) 
```

All 3 files: the ui.R, server.R, and test.Rmd are at the above absolute path

like image 127
Anthony Simon Mielniczuk Avatar answered Sep 21 '22 20:09

Anthony Simon Mielniczuk