1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Shinyで2つのInputから1つのOutputを操作する

1
Last updated at Posted at 2016-05-31

はじめに

  • Shinyでアプリケーションを作っていると、2つのInputから1つの同じアウトプット先を変更したいことがあります
    • 例:2つのインプットから、同じテキストレンダリングの値を変えたいなど
  • ちなみに、1つのアウトプットから、2つのOutputを変えるのは、reactive() を使うなどで簡単にできる
  • 正しいやり方なのかは不明ですが、動いたものを共有します

コードの例

server.R
# 2つのobserve()
observe({
    input$date
    output$create_date <- renderText({ 
      paste0(" 作成日:", format(isolate(input$date),"%Y/%m/%d"))
    })
})
observe({
    input$date_slider
    output$create_date <- renderText({ 
      paste0(" 作成日:", format(isolate(input$date_slider),"%Y/%m/%d"))
    })
})
ui.R
# Input 選択が2つ
dateInput('date',
          label = '日付選択:',
          value = Sys.Date() - 1
),
sliderInput(inputId="date_slider",
            label="日付アニメーション選択:",
            min=Sys.Date() - 7,
            max=Sys.Date(),
            value=Sys.Date(),
            step = 1,
            animate=animationOptions(interval=1500, loop=T),
            timeFormat = "%F"
)

<snip>

# Output 先
textOutput("create_date")

解説

  • observe で2つのInputに変更があるかを確認するようになる
  • isolate で囲まれているInputに変更がなければ実行されない

参考

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?