0
0

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 3 years have passed since last update.

Shinyでdebounceを使ってインプットの反映を遅らせる方法

Posted at

Shinyでは作成したinput要素がアプリ上で変更されると、自動的にそのinputが含まれる関数が更新されます。
例えば、下記のreactive関数があったとします。

ReactiveFunction = reactive({
  input$sample
  print(“reactive is updated”)
})

Shinyアプリ上で、sampleというIDのインプットを変更すると、ReactiveFunctionが更新され、print(“reactive is updated”)が実行されます。

もし、print(“reactive is updated”)の実行を、sampleというIDのインプットがShinyアプリ上で変更されてから1秒後にしたい場合は、下記のように書きます。

debounce(ReactiveFunction, 1000)

このように記載すると、sampleというインプットを1秒以内に連続で変更し続けた場合は、変更が1秒以上途切れるまで、print(“reactive is updated”)は実行されません。

インプットが変更されるたびに毎度毎度関数が更新されてほしくなく、ある程度間隔を置いてからインプットの変更が関数に反映されて欲しい時に上記のような書き方が有効です。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?