Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] Shiny interface deployed from RMarkdown script #799

Open
choldgraf opened this issue Sep 25, 2019 · 4 comments
Open

[feature request] Shiny interface deployed from RMarkdown script #799

choldgraf opened this issue Sep 25, 2019 · 4 comments

Comments

@choldgraf
Copy link
Member

an issue that was opened up in BinderHub (jupyterhub/binderhub#961) by @pablobernabeu :


Currently, running a Binder repo into the Shiny app interface (?urlpath=shiny) requires having a ui.R and a server.R script. I would like to make a feature request to enable a slightly different form of a Shiny app which is known as Flexdashboard.

A Flexdashboard is based on a single Rmarkdown (.rmd) script, which may have any name. In RStudio, the app is run through 'Run Document'. In the R console, it's run with rmarkdown::run('myfile.Rmd').

An example may be found in this repo, inside the 'Shiny-app' folder. Currently, the app can be run with the 'Run Document' button in RStudio, but not through the ?urlpath=shiny interface.

Thank you very much

@choldgraf
Copy link
Member Author

@pablobernabeu thanks for the suggestion! Could you list out the steps that would be needed to accomplish this locally?

My guess is that the change would need to be made in jupyter/repo2docker, and we'd basically need to add the logic in the R buildpack somewhere around here to decide "how" to launch a shiny server.

As with most things R-related, it'd be great if we can get some guidance from the R community on this one.

@pablobernabeu
Copy link
Contributor

pablobernabeu commented Sep 25, 2019

Thank you! This would be great.

Locally

To run the .rmd Shiny app locally, it just takes the following:

  1. Set R working directory to relevant folder, if necessary;
  2. Run app with rmarkdown::run('filename.rmd').

An example is available inside the 'Shiny-app' folder here: Binder

Binder Shiny interface

For the Shiny interface of Binder, I'd like to first mention that this type of Shiny app is relevant when there is a .rmd script that contains the string runtime:shiny (or runtime: shiny with one or two spaces after the colon).

This feature would introduce a .rmd script into the equation of the Shiny interface. Therefore it might be necessary to protect existing repos that use the Shiny interface and might potentially contain a .rmd file with runtime:shiny located in the same folder as the Shiny scripts. To avoid breaking the current Shiny interface of those repos, perhaps an approximate idea could be:

  • when the Shiny interface is called (i.e., as determined by ?urlpath=shiny being included in a Binder repo's URL),

    • if there are no ui.R and server.R files, and there is a .rmd script containing runtime:shiny (or runtime: shiny with one or two spaces after the colon),

then launch the .rmd script on Shiny with the two steps mentioned above.

Eventually, this URL would run: https://mybinder.org/v2/gh/pablobernabeu/Modality-exclusivity-norms-747-Dutch-English-replication/master?urlpath=shiny/Shiny-app/

I'd be glad to provide any further info, to the best of my knowledge.

pablobernabeu added a commit to pablobernabeu/repo2docker that referenced this issue May 9, 2020
…l as Section 3.2 at https://docs.rstudio.com/shiny-server/)

Installing (at least trying to install) `rmarkdown` library (for background, see jupyterhub#799, as well as Section 3.2 at https://docs.rstudio.com/shiny-server/)
@kaedonkers
Copy link

Hello!

Loving the R, RStudio, Jupyter Notebook and Jupyter Lab functionality in repo2docker/MyBinder! It's been super useful for supporting the scientists I work with to publish their work.

I have been trying to get RShiny from RMarkdown functionality to work on a Binder instance. Following what @pablobernabeu found in #891, I have only had success with the following (illustrative) repo configuration and Binder URLs:

.binder/
├─ runtime.txt
├─ install.R
├─ postBuild
analysis/
├─ index.Rmd
├─ analysis-subfolder.Rmd
.gitignore
index.Rmd
analysis-root.Rmd
LICENSE
README.md

The following URLs launch the RMarkdown as a Shiny app:

  1. https://mybinder.org/v2/gh/<user>/<repo>/main?urlpath=shiny (which renders index.Rmd)
  2. https://mybinder.org/v2/gh/<user>/<repo>/main?urlpath=shiny/index.Rmd (which also renders index.Rmd)
  3. https://mybinder.org/v2/gh/<user>/<repo>/main?urlpath=shiny/analysis-root.Rmd
    (which correctly renders analysis-root.Rmd)

The following do not work:

  1. https://mybinder.org/v2/gh/<user>/<repo>/main?urlpath=shiny/analysis
  2. https://mybinder.org/v2/gh/<user>/<repo>/main?urlpath=shiny/analysis/
  3. https://mybinder.org/v2/gh/<user>/<repo>/main?urlpath=shiny/analysis/index.Rmd
  4. https://mybinder.org/v2/gh/<user>/<repo>/main?urlpath=shiny/analysis/analysis-subfolder.Rmd

In this illustrative example all .Rmd files have runtime: shiny in their headers.

While the implementation of an .Rmd file in the main repo directory does work, it is quite inflexible. It would be much more useable for RShiny to pick up .Rmd files in a subdirectory like it does for RShiny configurations with server.R and ui.R files. How this might be implemented I don't know and can only point at @choldgraf's comment from earlier in this thread.

I am aware I could build on the rocker/binder Docker image like @pablobernabeu has done here which might well fix the problem, but I wish to use both Python and R examples in the same repo and so plan to use as much of the repo2docker infrastructure/automagic as possible.

@pablobernabeu
Copy link
Contributor

pablobernabeu commented Aug 16, 2022

Hi Kevin,

Only to underscore the issue about subdirectories, I'll note that the last app you referred to is located in the main directory. In contrast, I have an example of another Rmd app located in a subdirectory, and this app cannot be launched, as it produces a Not found error:

https://mybinder.org/v2/gh/pablobernabeu/Modality-exclusivity-norms-747-Dutch-English-replication/master?urlpath=shiny/Shiny-app/

However, the same app does launch when run inside the RStudio container: https://mybinder.org/v2/gh/pablobernabeu/Modality-exclusivity-norms-747-Dutch-English-replication/master?urlpath=rstudio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants