Mastering Shiny 08 User feedback

文章目录

  • [8 User feedback](#8 User feedback)
    • [8.1 Validation](#8.1 Validation)
      • [8.1.1 Validating input](#8.1.1 Validating input)
      • [8.1.2 Cancelling execution with `req()`](#8.1.2 Cancelling execution with req())
      • [8.1.3 `req()` and validation](#8.1.3 req() and validation)
      • [8.1.4 Validate output](#8.1.4 Validate output)
    • [8.2 Notifications](#8.2 Notifications)
      • [8.2.1 Transient notification](#8.2.1 Transient notification)
      • [8.2.2 Removing on completion](#8.2.2 Removing on completion)
      • [8.2.3 Progressive updates](#8.2.3 Progressive updates)
    • [8.3 Progress bars](#8.3 Progress bars)
      • [8.3.1 Shiny](#8.3.1 Shiny)
      • [8.3.2 Waiter](#8.3.2 Waiter)
      • [8.3.3 Spinners](#8.3.3 Spinners)
    • [8.4 Confirming and undoing](#8.4 Confirming and undoing)
      • [8.4.1 Explicit confirmation](#8.4.1 Explicit confirmation)
      • [8.4.2 Undoing an action](#8.4.2 Undoing an action)
      • [8.4.3 Trash](#8.4.3 Trash)
    • [8.5 Summary](#8.5 Summary)

8 User feedback

8.1 Validation

8.1.1 Validating input

复制代码
library(shiny);ui <- fluidPage(
  shinyFeedback::useShinyFeedback(),
  numericInput("n", "n", value = 10),
  textOutput("half")
)
server <- function(input, output, session) {
  half <- reactive({
    even <- input$n %% 2 == 0
    shinyFeedback::feedbackWarning("n", !even, "Please select an even number")
    input$n / 2    
  })
  output$half <- renderText(half())
};shinyApp(ui,server)

8.1.2 Cancelling execution with req()

复制代码
ui <- fluidPage(
  selectInput("language", "Language", choices = c("", "English", "Maori")),
  textInput("name", "Name"),
  textOutput("greeting")
)
server <- function(input, output, session) {
  greetings <- c(
    English = "Hello", 
    Maori = "Kia ora"
  )
  output$greeting <- renderText({
    req(input$language, input$name)
    paste0(greetings[[input$language]], " ", input$name, "!")
  })
}
}

8.1.3 req() and validation

复制代码
library(shiny);ui <- fluidPage(
  shinyFeedback::useShinyFeedback(),
  textInput("dataset", "Dataset name"), 
  tableOutput("data")
)
server <- function(input, output, session) {
  data <- reactive({
    req(input$dataset)
    exists <- exists(input$dataset, "package:datasets")
    shinyFeedback::feedbackDanger("dataset", !exists, "Unknown dataset")    
    req(exists, cancelOutput = T)
    get(input$dataset, "package:datasets")
  })
  output$data <- renderTable({
    head(data())
  })
};shinyApp(ui,server)

8.1.4 Validate output

复制代码
ui <- fluidPage(
  numericInput("x", "x", value = 0),
  selectInput("trans", "transformation", 
    choices = c("square", "log", "square-root")
  ),
  textOutput("out")
)
server <- function(input, output, session) {
  output$out <- renderText({
   	if (input$x < 0 && input$trans %in% c("log", "square-root")) {
      validate("x can not be negative for this transformation")
    }
    switch(input$trans,
      square = input$x ^ 2,
      "square-root" = sqrt(input$x),
      log = log(input$x)
    )
  })
};shinyApp(ui,server)

8.2 Notifications

复制代码
ui <- fluidPage(
  actionButton("goodnight", "Good night")
)
server <- function(input, output, session) {
  observeEvent(input$goodnight, { 
    showNotification("So long") 
    Sys.sleep(1)
    showNotification("Farewell")
    Sys.sleep(1)
    showNotification("Auf Wiedersehen")
    Sys.sleep(1)
    showNotification("Adieu")
  })
};shinyApp(ui,server)

8.2.1 Transient notification

8.2.2 Removing on completion

8.2.3 Progressive updates

8.3 Progress bars

8.3.1 Shiny

8.3.2 Waiter

8.3.3 Spinners

8.4 Confirming and undoing

8.4.1 Explicit confirmation

8.4.2 Undoing an action

8.4.3 Trash

8.5 Summary

相关推荐
Liue6123123120 小时前
自卸车多部件识别 _ Mask R-CNN改进模型实现(Caffe+FPN)_1
r语言·cnn·caffe
jiang_changsheng3 天前
环境管理工具全景图与深度对比
java·c语言·开发语言·c++·python·r语言
JicasdC123asd3 天前
使用Faster R-CNN模型训练汽车品牌与型号检测数据集 改进C4结构 优化汽车识别系统 多类别检测 VOC格式
r语言·cnn·汽车
请你喝好果汁6413 天前
## 学习笔记:R 语言中比例字符串的数值转换,如GeneRatio中5/100的处理
笔记·学习·r语言
怦怦蓝3 天前
DB2深度解析:从架构原理到与R语言的集成实践
开发语言·架构·r语言·db2
新新学长搞科研3 天前
【CCF主办 | 高认可度会议】第六届人工智能、大数据与算法国际学术会议(CAIBDA 2026)
大数据·开发语言·网络·人工智能·算法·r语言·中国计算机学会
Piar1231sdafa4 天前
战斗车辆状态识别与分类 --- 基于Mask R-CNN和RegNet的模型实现
r语言·cnn
陳土4 天前
R语言Offier包源码—1:read_docx()
r语言
善木科研喵4 天前
IF5.9分,α-硫辛酸如何缓解化疗神经毒性?网络毒理学结合网络药理学双重锁定关键通路!
数据库·数据分析·r语言·sci·生信分析·医学科研
Piar1231sdafa5 天前
椅子目标检测新突破:Cascade R-CNN模型详解与性能优化_1
目标检测·r语言·cnn