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

相关推荐
淮北49413 小时前
科研绘图工具R语言
开发语言·r语言
余醉 | dtminer2 天前
R语言常见新手问题
开发语言·r语言
佳哥的技术分享2 天前
Function<T, R> 中 apply,compose, andThen 方法总结
java·学习·r语言
2501_942191773 天前
纺织品微观缺陷检测与分类:基于Faster R-CNN的改进模型实现与性能优化_1
分类·r语言·cnn
TDengine (老段)3 天前
TDengine R 语言连接器进阶指南
大数据·开发语言·数据库·r语言·时序数据库·tdengine·涛思数据
Katecat996634 天前
肾衰竭医学影像多类别目标检测:基于Mask R-CNN的囊肿、肾脏、结石和肿瘤六类病变特征识别_1
目标检测·r语言·cnn
2501_942191774 天前
使用Faster R-CNN实现网球球检测:基于R50-FPN-MS-3x模型的COCO数据集训练与优化
目标跟踪·r语言·cnn
2501_941329724 天前
长豆荚目标检测:Faster R-CNN改进模型实战与优化
目标检测·r语言·cnn
一口面条一口蒜4 天前
R 包构建 + GitHub 部署全流程
开发语言·r语言·github