LoginSignup
2
0

More than 3 years have passed since last update.

R shinyapp.io で web アプリをデプロイしてみた

Last updated at Posted at 2021-03-04

はじめに

こちらの記事で簡単な R のアプリを試作してみた。これをshinyapps.ioを使ってデプロイしてみる。無料で5つまでのアプリケーションなら作成可能。

ユーザー登録

E-mail アドレスかgoogle ID, GitHub IDを使ってログインできる。メールアドレスでログインした場合、「Please verify your email address」のメールが届き、アドレスの確認を求められる。URLをクリックして登録が完了する。

パッケージのインストールとアプリの登録

Dashboard上の案内に従ってアプリの登録までを行ってみる。

STEP 1 – INSTALL RSCONNECT

アプリのデプロイにはrsconnectというパッケージが必要なよう。これをRコンソールからインストールする。

install.packages("rsconnect")

STEP 2 – AUTHORIZE ACCOUNT

アカウントの承認が必要なよう

The rsconnect package must be authorized to your account using a token and secret. To do this, click the copy button below and we'll copy the whole command you need to your clipboard. Just paste it into your console to authorize your account. Once you've entered the command successfully in R, that computer is now authorized to deploy applications to your shinyapps.io account.

rsconnectパッケージは、トークンとシークレットを使用してアカウントに承認する必要があるそう。承認を行うための必要なコマンドがクリップボードにコピーされるので、それをRコンソールに張り付けるだけでアカウントを承認できる。このコマンドを入力することで、そのコンピューターが shinyapp.io アカウントにアプリケーションを展開する許可を与える。

という事なので、実行してみる。

rsconnect::setAccountInfo(name='ryamamoto0406', token='XXXX', secret='XXXX')

特に戻り値などは無いよう。

STEP 3 – DEPLOY

Once the rsconnect package has been configured, you're ready to deploy your first application. If you haven't written any applications yet, you can also checkout the Getting Started Guide for instructions on how to deploy our demo application. Run the following code in your R console.

rsconnectパッケージを構成すると、最初のアプリケーションをデプロイする準備が整う。 まだアプリケーションを作成していない場合は、デモアプリケーションをデプロイする方法について、スタートガイドを確認することもできる。 Rコンソールで次のコードを実行する。

との事なので、こちらの記事で作ったアプリをデプロイしてみる。

library(rsconnect)
rsconnect::deployApp('path/to/your/app')
出力
Preparing to deploy application...DONE
Uploading bundle for application: 3733328...Detecting system locale ... ja_JA
DONE
Deploying bundle: 4298703 for application: 3733328 ...
Waiting for task: 882670952
  building: Processing bundle: 4298703
  building: Building image: 4915666
  building: Installing packages
  building: Installing files
  building: Pushing image: 4915666
  deploying: Starting instances
  rollforward: Activating new instances
  success: Stopping old instances
Application successfully deployed to https://ryamamoto0406.shinyapps.io/shiny_app/

となり、自動でデプロイできた。作ったアプリは https://ryamamoto0406.shinyapps.io/shiny_app/ でアクセスができる。

おわりに

shinyapp.io を使って簡単にアプリをデプロイすることができた。特に知識などは必要なかったので、今度はAWSなどの環境に shiny を導入し動かしてみる事などに挑戦してみたい。また、アプリも複雑なものを作っていきたいとも思う。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0