我目前正在制作一个闪亮的应用程序,我有一个功能可以使用"actionButton";以及原始数组文件中的同一行。然而,我想知道是否有一种方法可以在执行操作之前显示警告,询问用户是否确定要删除这一行(用shine、html或JS(。
以下是添加一行的示例:
#ui.R
BDD <- box(title = "Ajout d'un genre ou d'une famille dans la BDD",status = "primary",solidHeader=TRUE, width = 12,
fluidRow(
# column(12,fileInput(inputId="BDDtxt", label = "Selectionner le Fichier BDD des flore connues")),
column(4,textInput("Genus_Species", "Genre ou Espèce", value = "")),
column(5,offset = 2, textInput("description","Note sur la bacterie",value = "")),
column(12,checkboxGroupInput("flores","Marqueurs de ces flores :",c("Digestive","Cutanée","Oro-pharyngée","environementales"))),
column(4,offset=2,actionButton("ajouter", "Ajouter à la BDD")),
column(4,offset=1,actionButton("modifier", "Modifier la BDD"))
)
)
TabBDD <- box(title = "Affichage du tableau BDD",status = "primary",solidHeader=TRUE, width = 12,
fluidRow(
column(12,DT::dataTableOutput("TabBDD")),
column(12,offset=4,actionButton("selectionner","Sélectionner"))
)
)
#server.R
values <- reactiveValues(
TabBDD = NULL
)
observe({
if(file.exists("BDDflore.txt")) {
values$TabBDD <- read.delim("BDDflore.txt")
} else {
NULL
}
})
observeEvent(input$ajouter,{
Tab <- data.frame(
Species = input$Genus_Species,
Flore = paste(input$flores, collapse = ","),
Comment = input$description
)
write_delim(Tab,
file = "BDDflore.txt",
delim = "t",
append = TRUE)
if (is.null(values$TabBDD)) {
values$TabBDD <- Tab
} else {
values$TabBDD <- rbind(
values$TabBDD,
Tab
)
}
})
output$TabBDD <- DT::renderDataTable({
if(!is.null(values$TabBDD)){
values$TabBDD
}
})
#BDDflore.txt
Species Flora Comment
Propionibacterium acnes Cutanée Marqueur de la flore cutanée
提前感谢
也许使用shinyarert包,类似于
observeEvent(input$delete, {
shinyalert(
title = "Are you sure?",
text = "Delete row?",
showCancelButton = TRUE,
cancelButtonText = "No",
callbackR = function(ok) {
if(ok){
# R code to delete the row
}
}
)
})