添加观察器以显示通知
回顾:观察器用于产生副作用,例如在浏览器中显示图、表或文本。默认情况下,只要其依赖项发生变化,观察器就会触发相应动作。
在本练习中,您将使用 observe() 和 showNotification() 在浏览器中显示一条通知。由于我们是通过观察器来触发动作,因此不需要使用 render***() 函数,也不需要将结果赋给 output。
本练习是课程的一部分
使用 R 构建 Shiny Web 应用
练习说明
- 在 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)