Shiny中数据库错误时的错误警报

约瑟

我想知道如何创建一般警报,如果fileInput中加载的数据库与我的代码的理想基础不符,因为可能存在多个问题,例如:[.data.frame中的错误:选择了未定义的列,hclust中的错误:NA / NaN / Inf,以及其他错误。那么,有什么办法可以做到这一点?如果加载的数据库有问题,显示警报吗?我在可执行代码下方插入了仅用于测试的代码。可以从以下网站下载数据库:

https://github.com/JovaniSouza/JovaniSouza5/blob/master/Example.xlsx

library(shiny)
library(ggplot2)
library(shinythemes)
library(rdist)
library(geosphere)
library(rgdal)

function.cl<-function(df,k){
  
  #clusters
  coordinates<-df[c("Latitude","Longitude")]
  d<-as.dist(distm(coordinates[,2:1]))
  fit.average<-hclust(d,method="average") 
  clusters<-cutree(fit.average, k) 
  nclusters<-matrix(table(clusters))  
  df$cluster <- clusters 
  
  #all cluster data df1 and specific cluster df_spec_clust
  df1<-df[c("Latitude","Longitude")]
  df1$cluster<-as.factor(clusters)
  
  #Colors
  my_colors <- rainbow(length(df1$cluster))
  names(my_colors) <- df1$cluster
  
  #Scatter Plot for all clusters
  g <- ggplot(data = df1,  aes(x=Longitude, y=Latitude, color=cluster)) + 
    geom_point(aes(x=Longitude, y=Latitude), size = 4) +
    scale_color_manual("Legend", values = my_colors)
  plotGD <- g
  
  
  return(list(
    "Plot" = plotGD
  ))
}

ui <- bootstrapPage(
  navbarPage(theme = shinytheme("flatly"), collapsible = TRUE,
             "Cl", 
             tabPanel("Solution",
                      fileInput("data", h3("Excel import")), 
                      sidebarLayout(
                        sidebarPanel(
                          
                          sliderInput("Slider", h5(""),
                                      min = 2, max = 4, value = 3),
                        ),
                        mainPanel(
                          tabsetPanel(      
                            tabPanel("Solution", plotOutput("ScatterPlot"))))
                        
                      ))))

server <- function(input, output, session) {
  
  v <- reactiveValues(df = NULL)
  observeEvent(input$data, {
    v$df <- read_excel(input$data$datapath)
  })
  
  
  Modelcl<-reactive({if (!is.null(v$df)) {
    function.cl(v$df,input$Slider)
  }
  })
  
  
  output$ScatterPlot <- renderPlot({
    Modelcl()[[1]]
  })
  
  
}

shinyApp(ui = ui, server = server)
斯蒂芬·洛朗(Stephane Laurent)

也许像这样(我没有尝试过)。这需要的shinyWidgets软件包sendSweetAlert

Modelcl <- reactive({
  req(v$df)
  out <- NULL
  tryCatch({
    out <<- function.cl(v$df, input$Slider)
  }, error = function(e){
    sendSweetAlert(
      session, 
      "An error occured",
      "Try to upload another file.", 
      "error"
    )
  })
  out
})

output$ScatterPlot <- renderPlot({
  req(Modelcl())
  Modelcl()[[1]]
})

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Drupal 7 错误时间戳显示在自定义视图中,而不是数据库表中的内容

来自分类Dev

遇到数据库错误时,Codeigniter返回500内部服务器错误而不是错误消息

来自分类Dev

Codeigniter中的数据库错误1054

来自分类Dev

Codeigniter中的数据库错误1146

来自分类Dev

对Yii中的数据库的请求错误?

来自分类Dev

android中的sqlite数据库错误

来自分类Dev

选择数据库中的语句错误

来自分类Dev

Codeigniter 3.0.1中的数据库错误

来自分类Dev

还原数据库中的错误消息

来自分类Dev

TextWatcher 从数据库中错误选择

来自分类Dev

雪花数据库中的摄取错误

来自分类Dev

HSQLDB“精度或标超出范围”错误时UCanAccess加载数据库

来自分类Dev

如何解决close()从未在数据库错误时显式调用

来自分类Dev

Mirth:基于JS的数据库编写器中的错误触发的警报无法访问{messageId}?

来自分类Dev

在CodeIgniter中管理“发生数据库错误” 1062错误

来自分类Dev

数据库错误:FireBase 中的权限拒绝错误

来自分类Dev

更新数据库错误

来自分类Dev

WooCommerce数据库错误

来自分类Dev

压缩数据库错误

来自分类Dev

Codeigniter数据库错误

来自分类Dev

数据库登录错误

来自分类Dev

数据库输入错误

来自分类Dev

Laravel数据库错误

来自分类Dev

将数据插入数据库中的异常错误

来自分类Dev

数据获取查询中的数据库类错误

来自分类Dev

PHP从MySQL数据库错误中检索数据

来自分类Dev

更正数据库最新标志中的错误数据

来自分类Dev

Firebase 从数据库中检索错误的数据信息

来自分类Dev

SQLite数据库中不完整的SQL错误