開始使用免費開始

加入觀察器來顯示通知

回想一下,觀察器用於產生副作用,例如在瀏覽器中顯示圖表、 表格或文字。預設情況下,只要其底層相依性有變動,觀察器就會觸發動作。

在這個練習中,你會使用 observe()showNotification() 在瀏覽器中顯示通知。因為我們是用觀察器來觸發動作,所以不需要使用 render***() 函式,也不必把結果指定給 output

本練習屬於課程

使用 R 的 Shiny 建立網頁應用程式

檢視課程

練習說明

  • 在 server 中加入一個觀察器來顯示通知: 「You have entered the name xxxx」,其中 xxxx 為輸入的名稱。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

ui <- fluidPage(
  textInput('name', 'Enter your name')
)

server <- function(input, output, session) {
  # CODE BELOW: Add an observer to display a notification
  # 'You have entered the name xxxx' where xxxx is the name

  
  
  
  
}

shinyApp(ui = ui, server = server)
編輯並執行程式碼