11_timerは、コントロールなしで時刻のみをテキスト表示する例です。
「11_timer」の実行
library(shiny) runExample("11_timer")
server.R
function(input, output, session) { output$currentTime <- renderText({ invalidateLater(1000, session) paste("The current time is", Sys.time()) }) }
Code license:MIT
invalidateLater()
は、reactiveな動作を無効にするための関数。1000を指定すると、このsessionの実行内では、1秒間reactiveな動作が無効化される。そのため、output$currentTime
に出力される現在時刻の文字列は、1秒毎に更新される
ui.R
fluidPage( textOutput("currentTime") )
Code license:MIT
- サーバー側で
currentTime
に入力された時刻の文字列を、textOutput()
で表示する