我以前在Shiny告警中使用过,但是因为我尝试在shinyWidgets (ask_confirmation)中使用一些bug。在Shiny警报中,我使用callbackJS来了解用户是单击OK还是单击Cancel,但它在ask_confirmation中不起作用。
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
)
server <- function(input, output, session) {
ask_confirmation(
"form1",
title = " ",
type = "question",
btn_labels = c("Cancel", "OK"),
allowEscapeKey = TRUE,
closeOnClickOutside = TRUE,
html = TRUE,
#######################
#this one is not woking
callbackJS = "
function(x) {
if (x !== false) {
alert('t');
}
else{
alert('ttt');
}
}
",
######################
text =
div(HTML("
<form style = ' display:flex; flex-direction: row; justify-content: center; align-items: center' action=''>
<div style='border: 5px black;'>
<input type='text'name='add_nosha_tohen' autocomplete='off' id='add_nosha_tohen' value='' dir='rtl' style='border-color: black; font-size: 12px;height: 45px; width: 400px; display: block;'/></input>
</div>
</form>
"
))
)
}
shinyApp(ui, server)知道我该怎么修吗?
发布于 2022-06-29 22:24:32
在callbackJS中没有ask_confirmation参数。要执行回调,并运行JS代码,可以执行以下操作:
library(shiny)
library(shinyWidgets)
library(shinyjs)
ui <- fluidPage(
useShinyjs()
)
server <- function(input, output, session) {
ask_confirmation(
"form1",
title = " ",
type = "question",
btn_labels = c("Cancel", "OK"),
allowEscapeKey = TRUE,
closeOnClickOutside = TRUE,
html = TRUE,
######################
text =
div(HTML("
<form style = ' display:flex; flex-direction: row; justify-content: center; align-items: center' action=''>
<div style='border: 5px black;'>
<input type='text'name='add_nosha_tohen' autocomplete='off' id='add_nosha_tohen' value='' dir='rtl' style='border-color: black; font-size: 12px;height: 45px; width: 400px; display: block;'/></input>
</div>
</form>
"
))
)
observeEvent(input$form1, {
if(is.null(input$form1)) runjs("alert('NULL');")
else if (input$form1) runjs("alert('true');")
else runjs("alert('false');")
}, ignoreNULL = TRUE)
}
shinyApp(ui, server)

https://stackoverflow.com/questions/72799504
复制相似问题