How to Upload a Shiny App in Shinyapps.io
Shinyapps.io is a platform as a service (PaaS) for hosting Shiny spider web apps (applications). This article will prove you how to create a shinyapps.io business relationship and deploy your first awarding to the cloud.
Before you become started with shinyapps.io, you volition need:
- An R development environment, such every bit the RStudio IDE
- The latest version of the rsconnect R package
How to install rsconnect
The rsconnect parcel deploys applications to the shinyapps.io service. The rsconnect package is at present hosted on CRAN. Yous tin can install information technology by running the R control:
install.packages ( 'rsconnect' ) After the rsconnect bundle has been installed, load it into your R session:
library ( rsconnect ) Create a shinyapps.io account
Go to shinyapps.io and click "Dashboard." The site will ask you lot to sign in using your email and password, your Google account, or your GitHub business relationship.
The first time you sign in, shinyapps.io prompts you lot to prepare your business relationship. Shinyapps.io uses the account name as the domain name for all your apps. Account names must be betwixt 4 and 63 characters and can contain only messages, numbers, and dashes (-). Account names may not begin with a number or a dash, and they can not end with a dash (encounter RFC 952). Some account names may be reserved.
Configure rsconnect
Once you fix up your account in shinyapps.io, yous can configure the rsconnect package to utilize your account. Shinyapps.io automatically generates a token and secret for you, which the rsconnect bundle tin can employ to admission your account. Retrieve your token from the shinyapps.io dashboard. Tokens are listed nether Tokens in the carte at the top right of the shinyapps dashboard (under your avatar).
You tin configure the rsconnect package to employ your account with two methods:
Method ane
Click the show button on the token page. A window volition pop upwards that shows the full control to configure your business relationship using the appropriate parameters for the rsconnect::setAccountInfo function. Copy this command to your prune board, and and then paste information technology into the command line of RStudio and click enter.
Method ii
Run the 'setAccountInfo' function from the rsconnect package passing in the token and hole-and-corner from the Profile / Tokens page.
rsconnect :: setAccountInfo ( name = "<Account>" , token = "<TOKEN>" , secret = "<SECRET>" ) Once you have configured your rsconnect installation, you can utilize information technology to upload applications to shinyapps.io. In the second role of this guide, we will build a demo awarding, upload it to shinyapps.io, and create a password for the application.
If you're using the RStudio IDE, y'all tin manage your shinyapps.io accounts by going to Tools -> Global Options -> Publishing.
A Demo app
For this guide, we created an RStudio projection named "demo" that contains a Shiny application to upload to shinyapps.io. Follow these steps to create your own Shiny app.
Install awarding dependencies
The demo application nosotros will deploy requires the ggplot2 packet and the shiny package. Ensure that any package required past your application is installed locally earlier yous deploy your application:
install.packages ( c ( 'ggplot2' , 'shiny' )) ui.R and server.R
We placed two Shiny source files, ui.R and server.R, in our demo application. Y'all can cutting and paste the lawmaking below to make your own Shiny application:
server.R
library ( shiny ) library ( ggplot2 ) function ( input , output ) { dataset <- reactive ({ diamonds [ sample ( nrow ( diamonds ), input $ sampleSize ),] }) output $ plot <- renderPlot ({ p <- ggplot ( dataset (), aes_string ( x = input $ x , y = input $ y )) + geom_point () if ( input $ color != 'None' ) p <- p + aes_string ( color = input $ color ) facets <- paste ( input $ facet_row , '~' , input $ facet_col ) if ( facets != '. ~ .' ) p <- p + facet_grid ( facets ) if ( input $ jitter ) p <- p + geom_jitter () if ( input $ smooth ) p <- p + geom_smooth () print ( p ) }, height = 700 ) } ui.R
library ( shiny ) library ( ggplot2 ) dataset <- diamonds fluidPage ( titlePanel ( "Diamonds Explorer" ), sidebarPanel ( sliderInput ( 'sampleSize' , 'Sample Size' , min = ane , max = nrow ( dataset ), value = min ( g , nrow ( dataset )), step = 500 , round = 0 ), selectInput ( 'x' , '10' , names ( dataset )), selectInput ( 'y' , 'Y' , names ( dataset ), names ( dataset )[[ ii ]]), selectInput ( 'color' , 'Color' , c ( 'None' , names ( dataset ))), checkboxInput ( 'jitter' , 'Jitter' ), checkboxInput ( 'smooth' , 'Smooth' ), selectInput ( 'facet_row' , 'Facet Row' , c ( None = '.' , names ( dataset ))), selectInput ( 'facet_col' , 'Facet Column' , c ( None = '.' , names ( dataset ))) ), mainPanel ( plotOutput ( 'plot' ) ) ) Test your awarding
Examination that your application works by running information technology locally. Fix your working directory to your app directory, and then run:
library ( shiny ) runApp () If you're using the RStudio IDE, you tin can besides run your application by clicking the Run App button on the editor toolbar.
At present that the application works, permit's upload it to shinyapps.io.
Deploying apps
To deploy your awarding, use the deployApp control from the rsconnect packages.
library ( rsconnect ) deployApp ()
If yous're using the RStudio IDE, you tin can likewise deploy your awarding by clicking the Publish push button while viewing the awarding.
In one case the deployment finishes, your browser should open automatically to your newly deployed application.
Congratulations! You've deployed your first application. :-)
Feel free to make changes to your code and run deployApp again. rsconnect can deploy an app much more apace after the starting time deployment.
Bundle dependencies
When you lot deploy your awarding, the rsconnect package attempts to detect the packages that your application uses. rsconnect sends this list of packages and their dependencies along with your awarding to the shinyapps.io service. Then shinyapps.io builds and installs the packages into the R library for your application. The first time you deploy your application, it may take some time to build these packages (depending on how many packages are used). However, you will not expect for these packages to build during future deployments (unless you lot upgrade or downgrade a parcel).
Package sources
Currently the shinyapps.io service supports deploying packages installed from CRAN, GitHub, and BioConductor. We will look to add support for R-Forge packages in the future.
Important note on GitHub packages
Only packages installed from GitHub with devtools::install_github in version ane.4 (or subsequently) of devtools are supported. Packages installed with an before version of devtools must exist reinstalled earlier you tin can deploy your application. If you go an error such as "PackageSourceError" when you lot attempt to deploy, check that yous accept installed any bundle from Github with devtools ane.4 or later.
Application instances
Shinyapps.io hosts each app on its ain virtualized server, called an instance. Each instance runs an identical copy of the code and packages that yous deployed (chosen the image).
When you deploy an app, shinyapps.io creates a new image with the updated code and packages, and starts i or more instances with the new prototype. If the app was previously deployed, shinyapps.io shuts downwards and destroys the old instances. Consider a few implications of this arrangement:
1) Data written by an application to the local filesystem of an case volition exist lost when y'all re-deploy the app. Additionally, the distributed nature of the shinyapps.io platform means that instances may be shut downward and re-created at any time for maintenance or to recover from server failures.
two) It is possible to have more than one instance of an application. This situation means that multiple instances of an application exercise not share a local filesystem. A file written to ane example will not be available to another case.
Shinyapps.io limits the amount of organisation resources an example can swallow. The amount of resources bachelor to an instance will depend on its blazon. The table beneath outlines the diverse case types and how much memory is immune. By default, shinyapps.io deploys all applications on 'medium' instances, which are allowed to use 512 MB of memory.
| Example Blazon | Retentiveness |
|---|---|
| pocket-sized | 256 MB |
| medium (default) | 512 MB |
| large | 1024 MB |
| xlarge | 2048 MB |
| xxlarge | 4096 MB |
Note: Instance types and limits are non finalized; RStudio may alter them in the futurity.
Application logging
If yous're having bug with your application, it may be helpful to be able to see the log letters it'due south producing. Yous can use the rsconnect::showLogs() function to show the log messages of a deployed awarding. This log will include both stdout (log lines producted via print or cat) and stderr (log lines produced past bulletin, alert, stop). You lot tin can even utilize the streaming=True option to specify that you want to continuously monitor the file for changes; this will listen for log messages until you interrupt R (typically by pressing Escape). If you deployed your application using an older version of the rsconnect package, y'all volition need to redeploy it (deployApp(upload=Simulated)) before you tin use logging.
Configuring applications
You can change the instance type used by an application with the configureApp office from the rsconnect package. To change the instance blazon of your awarding (here from medium to pocket-sized), run:
rsconnect :: configureApp ( "APPNAME" , size = "pocket-sized" ) This modify will redeploy your application using the small instance type.
You tin can also change the instance type used by an awarding from the shinyapps.io dashboard. To do this, log in to shinyapps.io, select the awarding that you wish to configure, and and so open up the Settings tab.
To learn more than nearly instances and other details of the shinyapps.io compages, read Scaling and Functioning Tuning. The guide will besides testify you several advanced options for fine tuning the operation of your apps on shinyapps.io.
Awarding authentication
With shinyapps.io, yous tin limit the admission to your application by enabling authentication. Only users who log-in with valid credentials will be able to view or utilise the app.
To enable authentication in the administrative UI, select the application to modify and click on the Users tab.
Here is a sample application with the default visibility settings:
Alter the Application Visibility to Private and click on Relieve Settings. Changing the visibility of your application will crave a restart of the awarding. The Owner of the account and other members of the account volition automatically be included in the listing of authorized users.
After the awarding is restarted you can add authorized users past entering their e-mail addresses and clicking on Add User.
Each user will receive an email from shinyapps.io with an invite to view your awarding. If a user does not already have an authenticated account on shinyapps.io, they volition be able to create i by authenticating through i of the following three methods:
- Google Say-so
- GitHub authorisation
- Shinyapps.io authentication
Shinyapps.io will prompt each visitor to your app for a username and password if they have not been authenticated. Only users who log-in with valid credentials will be able to view or apply the app.
If you currently use the pre-beta authentication scheme, please upgrade to the new system by January 28, 2015 as we will be deprecating support for the erstwhile authentication system during the beta. For instructions on how to upgrade, please read the guide hither.
Finish an app
You can remove an app on shinyapps.io from the web with the terminateApp command. To use it, run
terminateApp ( "<your app's name>" ) terminateApp requires one argument, the proper noun of the app that you would like to finish (as a character string). This proper name should stand for with one of the apps in your shinyapps.io business relationship.
When you run terminateApp shinyapps.io will close your app, only the app volition remain archived in your shinyapps.io account. This creates efficiencies if you later decide to redeploy your app with deployApp.
You can also end an app from your shinyapps.io dashboard. To do this, log in to shinyapps.io, select the app that you wish to terminate and so click "Annal."
Getting assist
To seek and share advice about shinyapps.io, please visit the Shinyapps.io google group.
Epitomize
Shinyapps.io is an online service for hosting Shiny apps in the cloud. RStudio takes care of all of the details of hosting the app and maintaining the server, which lets you focus on writing bang-up apps!
To use shinyApps.io
- Install the rsconnect R packet from github
- Create an account at shinyapps.io
- Use the tokens generated by shinyapps.io to configure your
rsconnectpacket. - Deploy apps with
rsconnect::deployApp - End apps with
rsconnect::terminateApp
Y'all tin can also utilise shinyapps.io to create secure apps, and manage your authorized users.
Learn more
For more on this topic, see the following resources:
Shinyapps.io Overview & Bout
If y'all have questions about this article or would like to discuss ideas presented here, please mail service on RStudio Customs. Our developers monitor these forums and answer questions periodically. See help for more assistance with all things Shiny.
bernacchithounater.blogspot.com
Source: https://shiny.rstudio.com/articles/shinyapps.html
0 Response to "How to Upload a Shiny App in Shinyapps.io"
Post a Comment