using a shiny app for the shiny-server landing page

1,136 views
Skip to first unread message

Clifford Long

unread,
May 30, 2017, 11:46:17 AM5/30/17
to Shiny - Web Framework for R
Dear All,

I have a question, if I may.

We have developed a growing number of shiny apps that we use often.  ("Thank you!" to the authors of shiny, shiny-server)

We host these shiny apps on a Linux server (Red Hat) within our corporate firewall.


OUR SYSTEM
Red Hat: Red Hat Enterprise Linux Server release 6.9 (Santiago)
shiny-server:  Shiny Server v1.3.0.403  Node.js v0.10.21
shiny:  1.0.3
R:  R version 3.3.3


Our setup on the server is based on the shiny-server instructions and basic setup.  We have a folder "opt" which has a matching "srv" folder (apologies if this is redundant ... I'm new to Linux and servers).  Within the 'srv' folder we have the 'shiny-server' folder.  The landing page "index.html" file is in the 'shiny-server' folder along with the css file.  We then created two subfolders, one for production apps ('production-apps') and one for development apps ('development-apps').  We publish links to apps in the 'production-apps' folder on the shiny-server landing page.  This approach has worked well so far.


THE ISSUE
For the landing page we started with html/css.  We then decided to explore the use of a shiny app and markdown to provide the landing page.  The shiny app uses server.R and ui.R files located within the 'shiny-server' directory (where the 'index.html' file was previously kept).  The UI is based on navbarPage, and each page draws content from an ".md" file.

When we used the 'index.html' approach all of the links worked well.

When we switched to the shiny app and .md approach for the shiny-server landing page we encountered some difficulty.  We can no longer link to subfolders such as 'development-apps'.  For example, http://10.2.13.27:3838/development-apps/ would provide a directory listing when we use the landing page based on html/css ('index.html').  When we switch to using the shiny navbarpage as the shiny-server landing page we can no longer access this URL path - we get an error message ("Not Found").  We also get this when we link directly to an app directory (http://dev2-deming.essendant.com/production-apps/itbq_facility_report).

Is the use of a shiny app (ui.R, server.R) for the shiny-server landing page just not a good practice?  Or is it OK to do this and we are just missing some setting that would allow us to access/link-to shiny-server subdirectories and apps if we use a shiny app for the shiny-server landing page?

Thank you in advance for any guidance that might be provided.  And apologies in advance for any shortcoming with the question.

Cliff


Joe Cheng

unread,
Jun 1, 2017, 4:18:20 AM6/1/17
to Clifford Long, Shiny - Web Framework for R
This is fine but in your /etc/shiny-server/shiny-server.conf you need to add two new locations, one for each subdirectory, as siblings to the "location /" block you already have. And they must come before the location /. See below for an example.

The reason this is necessary is because once a Shiny app is found in a parent URL (in this case the URL being requested is http://server:3838/production-apps/ but there's an app in http://server:3838/) the URL is passed to the Shiny app to handle. And since subdirectories of Shiny apps are assumed to be private (unless they have the special name "www") then you get a Not Found error. Adding the additional location directives to eh config, and putting them above the original location directive, explicitly tells Shiny Server to treat those two particular URL paths (and their subpaths) as being distinct from the top-level Shiny app.

Before:

# Instruct Shiny Server to run applications as the user "shiny"
run_as shiny;

# Define a server that listens on port 3838
server {
  listen 3838;

  # Define a location at the base URL
  location / {

    # Host the directory of Shiny Apps stored in this directory
    site_dir /srv/shiny-server;

    # Log all Shiny output to files in this directory
    log_dir /var/log/shiny-server;

    # When a user visits the base URL rather than a particular application,
    # an index of the applications available in this directory will be shown.
    directory_index on;
  }
}

After:

# Instruct Shiny Server to run applications as the user "shiny"
run_as shiny;

# Define a server that listens on port 3838
server {
  listen 3838;

  location /production-apps {
    site_dir /srv/shiny-server/production-apps;
    log_dir /var/log/shiny-server;
    directory_index on;
  }

  location /development-apps {
    site_dir /srv/shiny-server/development-apps;
    log_dir /var/log/shiny-server;
    directory_index on;
  }

  location / {

    # Host the directory of Shiny Apps stored in this directory
    site_dir /srv/shiny-server;

    # Log all Shiny output to files in this directory
    log_dir /var/log/shiny-server;

    # When a user visits the base URL rather than a particular application,
    # an index of the applications available in this directory will be shown.
    directory_index on;
  }
}


--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/161dcb0e-e31c-4707-bc91-1ccdfe553609%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Clifford Long

unread,
Jun 1, 2017, 10:00:03 AM6/1/17
to Shiny - Web Framework for R, crlon...@gmail.com
Hi Joe.  Many thanks for the reply (and at the early hour).  It worked.

Thanks again for a great system.

Cliff
Reply all
Reply to author
Forward
0 new messages