LoginSignup
4
3

More than 5 years have passed since last update.

Shinyでダイアログを出すのが標準機能でできるようになってた

Last updated at Posted at 2016-11-11

Shinyの0.14以降ではダイアログを標準機能で出せるようになりました。普通に検索するとshinyBSパッケージを使用したり、JavaScript(後述)を使用したりする記事が多く出てきますのでご注意ください。
modal-dialogs
Screenshot_20161111-151600.png

コード

showModal(modalDialog(title = "エラー", "入力が正しくありません", easyClose = TRUE, footer = modalButton("OK")))

オプション

  • title: ダイアログのタイトル
  • size: ダイアログの幅、s/m(標準)/l
  • footer: dismissボタンをつけるかどうか
  • easyClose: ダイアログの外をクリックすると閉じれるようにするかどうか

参考:古い方法

Javascriptを利用する方法は以下になります。のっぴきならない理由でver0.13以前を使わなくてはならないとかいうケースは従来通りの方法をご利用ください、、、。

ui.R

tags$head(
  tags$script(HTML('Shiny.addCustomMessageHandler("jsCode",function(message) {eval(message.value);});'))
)

server.R

session$sendCustomMessage(type='jsCode', list(value = 'alert("エラー");'))
4
3
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
4
3