Shiny Server URL

Skip to first unread message

taylora...@gmail.com

unread,
Sep 11, 2013, 8:24:58 AM9/11/13
to shiny-...@googlegroups.com
Do I need to use Shiny Server for my shiny apps if I already have my own server?

Also, with Shiny Server, what will the URL of the shiny app look like?

Thanks for any help!

ZJ

unread,
Sep 11, 2013, 8:55:02 AM9/11/13
to shiny-...@googlegroups.com
https://github.com/rstudio/shiny-server/wiki/Ubuntu-step-by-step-install-instructions

I think there is some installation instructions for Ubuntu. 

Jeff Allen

unread,
Sep 11, 2013, 12:47:07 PM9/11/13
to shiny-...@googlegroups.com
(Thanks for bringing the question over here, Taylor).

We'd recommend using Shiny Server for any real hosting of Shiny Apps. Shiny by itself would be a bit of a headache to manage (you'd have to spin up R and maintain R processes for each Shiny application you want to host, map them to particular ports, etc.) Shiny Server handles all that for you so you can have a single daemon process on the server that hosts all of these applications for you (and offers a variety of other perks as seen on the README of the GitHub project).

Regarding the URL, I apologize that we don't have this formally documented publicly just yet. However, we're just finishing up the first draft of some documentation internally, and I can post the relevant section to you here. The short answer is: pick a port on which you want Shiny Server to run then you can setup your URLs be prefaced by whatever you want. Documentation is copied below (sorry if the formatting gets weird in email. If it's unreadable, let me know and I can generate a PDF).

Jeff


Server Hierarchy

Detailed descriptions of all available parameters are available in the appendix, but it is important to understand the overall hierarchy of the Shiny Server configuration file when editing the file.

Server

The server setting defines an HTTP server which will listen on a port/IP address combination. For example, the following lines:

server {
  listen 80;
}

define a server that would listen on port 80. A server can also define a server_name to limit the virtual hostnames on which it listens, as described in the Virtual Hosts section.

Location

The location setting is defined within a server and defines how a particular URL path should be served. For instance, the following settings:

server {
  ...
  # Define the location '/specialApp'
  location /specialApp {
    # Run this location in 'app_dir' mode, which will host a single Shiny
    # Application available at '/srv/shiny-server/myApp'
    app_dir /srv/shiny-server/myApp
  }
  
  # Define the location '/otherApps'
  location /otherApps {
    # Run this location in 'site_dir' mode, which hosts the entire directory
    # tree at '/srv/shiny-server/apps'
    site_dir /srv/shiny-server/apps;
  }
...
}

would define two locations, one which serves (potentially) a multitude of applications at the URL /otherApps/, and another which serves a single application at the URL /specialApp/.

The various hosting models which can be applied to a location are described in the section on Hosting Models.

Application

The application block is specified within a location and defines the settings related to a particular application. The application is referenced by the directory in which it is stored. For example, the following configuration could be used to modify the application housed at /srv/shiny-server/app1.

...
location / {
  # Define rules to apply to one application, stored at '/srv/shiny-server/app1'
  application /srv/shiny-server/app1 {
    simple_scheduler;
  }
}
...

This block would specify that, within this location, the referenced application should use the Simple Scheduler. This setting would have no effect on the other applications hosted in this location block.




Hosting Model

There are currently four different methods of configuring a location, three of which serve Shiny applications. These three are described below; see the following section on Redirecting to learn about a fourth mode.

app_dir

A location configured to use app_dir will attempt to serve a single application hosted at the given directory. For instance,

# Define the location '/specialApp'
location /specialApp {
  app_dir /srv/shiny-server/myApp;
}

will configure the location responsible for the path /specialApp to use this app_dir router which serves a single application stored in the directory /srv/shiny-server/myApp. This configuration would presume a server.R file (and corresponding ui.R file) would be available at /srv/shiny-server/myApp/server.R.

site_dir

A location which uses site_dir will host an entire directory tree -- both Shiny Apps and static assets.

# Define the location '/'
location / {
  site_dir /srv/shiny-server/
}

The above configuration would instruct Shiny Server to make the /srv/shiny-server/ directory available at the base URL. Any Shiny applications stored in this directory (or any subdirectory), along with any static assets (including images, data, JavaScript/CSS files, etc.) will be made available at the corresponding URL. For example, see the following directory tree:

+---/srv/shiny-server
|   +---shinyApp1
|       +---server.R
|       +---ui.R
|   +---shinyApp2
|       +---server.R
|       +---ui.R
|   +---assets
|       +---style.css
|       +---script.js

If this server were available at http://server.com, the location settings above would make the following (along with any other file in the tree) publicly available to the user.

http://server.com/shinyApp1

Serve the Shiny App defined in 'shinyApp1'

http://server.com/shinyApp2

Serve the Shiny App defined in 'shinyApp2'

http://server.com/assets/style.css

Serve this static CSS file

http://server.com/assets/script.js

Serve this static JS file

user_apps

A location configured to use user_apps will allow users on the system to create and manage their own Shiny applications available in their home directories. This directive will host any application stored in an eligible user's ~/ShinyApps directory publicly at a URL prefaced by their username.

This privilege can be restricted only to users of particular groups using the members_of restriction. For instance, the following configuration:

# Define the location '/userApps'
location /userApps {
  user_apps;
  
  # Only allow members of the 'shinyUsers' group to host personal applications.
  members_of shinyUsers;
}

will -- for any user who is a member of the shinyUsers group -- publicly host any Shiny application available in the user's ~/ShinyApps directory.

Alex Bokov

unread,
Sep 24, 2013, 10:12:59 AM9/24/13
to shiny-...@googlegroups.com
If a user has a static, frequently accessed file that I don't want to clutter up the /tmp directory with, is there a directory in ~/ShinyApps they can create to make it downloadable via direct link, without a downloadHandler?

Joe Cheng

unread,
Sep 24, 2013, 10:41:00 AM9/24/13
to shiny-...@googlegroups.com
Yes, put it in a "www" subdirectory of your app directory, and then you can use a relative URL (don't include the "www" in the path) to refer to it. For example, www/foo.txt would be at tags$a(href="foo.txt").
--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Alex Bokov

unread,
Sep 24, 2013, 11:34:37 AM9/24/13
to shiny-...@googlegroups.com
Thanks!

Haohua Tang

unread,
Apr 20, 2014, 10:40:52 PM4/20/14
to shiny-...@googlegroups.com
Hi Joe, 

Thank you for putting together all the shiny thing. It is a great tool. 

I have a question using the www/file to share the files through shiny server. 

I have an issue to host the directory under shiny sever.

In my shiny-server.conf, i put the following 
server {
listen 3838;
location /model1 {
site_dir /data/model;
log_dir /var/log/shiny-server;
directory_index on;
}
}

The app is working, but i cannot access the files under the directory. 
For example, the http://server:3838/model1 ( app link) works, 
but i cannot access to any file under the site_dir, or any link as 
http://server:3838/model1/test.pdf doesn't work.

Can you help me to solve this issue, or point to the right direction? Thanks.

Also,i notice that, even if i set the listen port to be 3838, everytime the shiny-server log file will show that the app is running at some random port number, e.g. 12345 not 3838. 
Is this what shiny-server do, or i need to change some configuration file?

thanks 
andy

To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discuss+unsubscribe@googlegroups.com.

jeem0...@gmail.com

unread,
May 11, 2016, 10:54:10 PM5/11/16
to Shiny - Web Framework for R
I know this post is quite long but I am facing the problem below and it seems that nobody can resolve this. Once the random port number kicks in, it will be block by my firewall rules.

Also,i notice that, even if i set the listen port to be 3838, everytime the shiny-server log file will show that the app is running at some random port number, e.g. 12345 not 3838. 

Joe Cheng

unread,
May 12, 2016, 1:55:49 AM5/12/16
to jeem0...@gmail.com, Shiny - Web Framework for R
Port 3838 is the (default) port that Shiny Server listens on. Shiny Server then launches multiple R processes to run the actual Shiny apps; these also need ports to listen on, and they can't be 3838 as it is taken by Shiny Server. So they listen on random ports chosen by Shiny Server. However, these ports can only be accessed from localhost, and furthermore a "shared secret" is passed from Shiny Server to each Shiny process so that no other processes can perform requests against those random ports.

Please configure your firewall not to block ports on 127.0.0.1, and it should work.

To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

--
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/8ab3b80e-8835-49d8-9eb9-18e0080fd384%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jeem0...@gmail.com

unread,
May 12, 2016, 3:26:32 AM5/12/16
to Shiny - Web Framework for R, jeem0...@gmail.com
Thanks Joe Cheng,

Your reply is god sent and I finally manage to resolve this problem after so long. Good job. The below 2 lines is added to the /etc/sysconfig/iptables

-A INPUT -i lo -j ACCEPT
-A OUTPUT -o lo -j ACCEPT
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discuss+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages