当fileInput中插入的文件与“ .xlsx”,“。shp”,“。shx”,“。dbf”不同时,我想插入一条警报消息。你能帮助我吗?我在下面输入了可执行代码。您甚至可以在我的watchEvent(input $ data,我插入了类似的东西,但我希望将其显示为Shiny中的文本框的方式中看到它。
谢谢!
//main.cpp
#include "ClassA.h"
int main()
{
ClassA obj;
obj.function3();
}
答案 0 :(得分:1)
正如@StéphaneLaurent在评论中指出的那样,shinyWidgets
可用于显示甜蜜警报。对于某些输入,{shinyFeedback}软件包也可以使用,但是,尚不支持fileInput
。
以下是使用sendSweetAlert
代替您的print
调用的一种可能的实现方式。
library(shiny)
library(shinyWidgets)
library(ggplot2)
library(shinythemes)
library(rdist)
library(openxlsx)
library(geosphere)
library(rgdal)
function.cl<-function(df,k){
}
ui <- bootstrapPage(
navbarPage(theme = shinytheme("flatly"), collapsible = TRUE,
"Cl",
tabPanel("Solution",
fileInput("data", h3("Excel or Shapefile import"),
accept = c(".xlsx",".shp",".shx",".dbf"),
multiple= T),
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, {
if(any(grepl(".xlsx",input$data$name))){
v$df <- read.xlsx(input$data$datapath)
}else if(any(grepl(".shp",input$data$name))){
shpDF <- input$data
failed <- F
if(!any(grepl(".shx",input$data$name))){
failed<-T
}
if(!any(grepl(".dbf",input$data$name))){
failed<-T
}
if(failed){
sendSweetAlert(
session = session,
title = "Error !!",
text = "You Need 3 files, '*.shp', '*shx' and '*.dbf'",
type = "error"
)
}else{
prevWD <- getwd()
uploadDirectory <- dirname(shpDF$datapath[1])
setwd(uploadDirectory)
for (i in 1:nrow(shpDF)){
file.rename(shpDF$datapath[i], shpDF$name[i])
}
shpName <- shpDF$name[grep(x=shpDF$name, pattern="*.shp")]
shpName<-substr(shpName,1,nchar(shpName)-4)
setwd(prevWD)
shpFile<-readOGR(dsn=uploadDirectory,layer=shpName)
v$df<-shpFile@data
}
}else{
sendSweetAlert(
session = session,
title = "Error !!",
text = "Wrong File",
type = "error"
)
}
})
Modelcl<-reactive({if (!is.null(v$df)) {
function.cl(v$df,input$Slider)
}
})
output$ScatterPlot <- renderPlot({
Modelcl()[[1]]
})
}
shinyApp(ui = ui, server = server)