5

When having a shiny app set up like this for the shiny server

+---/srv/shiny-server
|   +---shinyApp1
|       +---server.R
|       +---ui.R

all works fine. However, how can I do the same, when the above files (ui.R, server.R) are included in a packages inst/shiny folder? (see, for example, my gridsampler repo).

How can I deploy a packaged shiny app on shiny server?

Mark Heckmann
  • 10,943
  • 4
  • 56
  • 88

2 Answers2

6

You can do what I do.

I host a lot of shiny apps from packages on my shiny server and what I do is just setwd() to the directory of the shiny app and then call shinyAppDir(".").

As an example: this code is responsible for this app


Edit 2.5 years later: note that this will not work if you have a global.R file - see this issue on github https://github.com/rstudio/shiny/issues/1063

My workaround for that is to explicitly source global.R

DeanAttali
  • 25,268
  • 10
  • 92
  • 118
  • This is a nice solution. Thanks. – Mark Heckmann Aug 21 '16 at 19:59
  • 1
    I agree, I'll probably use this method from here on out, too. – Jemus42 Aug 21 '16 at 21:51
  • Tried it, but I get an error about the app not finding variables defines in `global.R` – Can't seem to figure out why. The symlink-method I suggested works, though. – Jemus42 Aug 22 '16 at 11:11
  • Did some digging, `global.R` doesn't work intentionally in this configuration, but there are workarounds (like explicitly source'ing it), and now it works. Discussion here: https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/shiny-discuss/ibAXs3zLWAs/YOVRVRU2AQAJ – Jemus42 Aug 22 '16 at 11:41
  • 3
    Yes that's true. I do find that annoying. I opened a bug about that in RStudio's github issues a long time ago, feel free to add your opinion there to show them that other people also think it's annoying :) My workaround is to explicitly source global.R – DeanAttali Aug 22 '16 at 18:02
2

I went for the easy way and just cloned the package from GitHub into the shiny-server directory and have to manually link to the inst/shiny subdirectory, see my hosted version of gridsampler as an example (notice the non-pretty URL). The shiny-server is set up to host a directory of apps, hence the overview when visiting the root URL where you need to click through to the app.

Other possibilities might include cloning the repository somewhere outside the shiny-server folder and symlinking the inst/shiny folder into the shiny-server folder as gridsampler, which afaik should work if appropriate permissions are set.

Jemus42
  • 629
  • 9
  • 24
  • how do you link to the `inst/shiny` subdirectory? In the server config or what do mean by linking. Can you elaborate? – Mark Heckmann Aug 21 '16 at 16:13
  • @MarkHeckmann Linking as in "copy the URL to that subdirectory", i.e. `https://gauss.tadaa-data.de/projects/gridsampler/inst/shiny/` – This may require the shiny-server to be set up to host a directory of app, see http://docs.rstudio.com/shiny-server/#host-a-directory-of-applications for config info. My shiny server is set up like that and the server root looks like this: https://paste.xinu.at/2Lojkf/ – Jemus42 Aug 21 '16 at 16:22
  • 1
    I think an even easier way is to just run the app from the installed directory using `shinyAppDir()` – DeanAttali Aug 21 '16 at 19:23
  • @DeanAttali, Is it possible to install "https://github.com/JinmiaoChenLab/cytofkit2/blob/master/R/cytofkit_shinyAPP.R" in the R Shiny server running on ubuntu? If so, can you kindly advise how? – RanonKahn Feb 12 '21 at 02:48