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

相关推荐
生物信息与育种7 小时前
全基因组重测序及群体遗传与进化分析技术服务指南
人工智能·深度学习·算法·数据分析·r语言
l1t7 小时前
在aarch64机器上安装使用R语言的季节调整包
开发语言·r语言
知识分享小能手9 小时前
R语言入门学习教程,从入门到精通,R语言分布式数据可视化(6)
学习·信息可视化·r语言
知识分享小能手1 天前
R语言入门学习教程,从入门到精通,R语言数值关系数据可视化 - 完整知识点(5)
学习·信息可视化·r语言
生信碱移2 天前
PACells:这个方法可以鉴定疾病/预后相关的重要细胞亚群,作者提供的代码流程可以学习起来了,甚至兼容转录组与 ATAC 两种数据类型!
人工智能·学习·算法·机器学习·数据挖掘·数据分析·r语言
知识分享小能手2 天前
R语言入门学习教程,从入门到精通,R语言类别比较数据可视化- 完整知识点与案例代码(4)
学习·信息可视化·r语言
星座5282 天前
掌握双碳核心工具,从产品碳足迹到气候变化响应:基于OpenLCA、GREET、R语言的生命周期评价方法、模型构建及典型案例应用
r语言·生命周期·openlca·greet
知识分享小能手3 天前
R语言入门学习教程,从入门到精通,R语言网格绘图系统(ggplot2)- 完整知识点与案例代码(3)
开发语言·学习·r语言
做cv的小昊3 天前
【TJU】研究生应用统计学课程笔记(5)——第二章 参数估计(2.3 C-R不等式)
c语言·笔记·线性代数·机器学习·数学建模·r语言·概率论
hhb_6184 天前
R语言数据分析与可视化实战指南
开发语言·数据分析·r语言