LoginSignup
4
4

More than 5 years have passed since last update.

ShinyでsliderInputを日付で選択する

Posted at

はじめに

  • 興味でShinyでダッシュボードを構築してると、sliderInputを日付で選択できると便利だなーと思って調べた
  • ググッても簡単に事例は出てこなかったので、やり方を共有

Shiny Issue

  • #689で議論されていた。
  • wchさんがまだ実装されていないとおっしゃっている…!
  • 「がーん」と思ったら、そのままの流れで、wchさん実装したものがMergedされている!よし。

Slider Input Widget

  • 公式マニュアルはこちら。timeFormatのところでできそうな雰囲気を感じた。
  • input-slider.R
    • コードはこちら。81行目あたりから見る限り、sliderInputのmin valueをinheritでDateやPOSIXで指定できてる。

書き方

下記のように書く

app.R
sliderInput(inputId="sliderDate",
             label="日付選択 : 2015/12/01-11",
             min=as.Date("2015-12-1"),
             max=as.Date("2015-12-11"),
             value=as.Date("2015-12-1"),
             step = 1,
             animate=animationOptions(interval=1500, loop=T),
             timeFormat = "%F"
            )

結果

期待どおりのsliderInputになった

スクリーンショット 2015-12-13 0.29.10.png

おわりに

  • Shiny便利。データはあらかじめ整形してRDSで保存してそれを読んでそのまま可視化するくらいなら、十分な速度で動く。アプリレイヤーは自分は全然書けないで人に見せるときに色々と助かる。
    • あらかじめ見せるものが決まってるダッシュボードとして使うのに良い。Shinyの上で分析や試行錯誤は処理速度の関係上辛いなーという印象。
4
4
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
4