在Shiny应用程序中更改bsModal的背景 [英] Change backdrop for a bsModal in Shiny app
问题描述
我正在开发一个Shiny应用程序,我需要确保最终用户不会意外关闭bsModal,因为上面有一些操作按钮.我已经进行了一些研究,并了解到需要覆盖背景和键盘参数,但是即使看到了一些建议,我也不知道在代码中应该确切地放置这些内容.我不精通JavaScript,对Shiny还是很陌生,因此即使感觉很简单,我也无法做到这一点.
I am developing a Shiny app and I need to make sure the end users won't accidentally close a bsModal, because there are some action buttons on it. I've done some research and learned I need to overwrite backdrop and keyboard parameters, but even though I've seen some suggestions, I have no idea where exactly this needs to sit in my code. I am not proficient with JavaScript and very new to Shiny, so even though it feels like a simple task, I cannot get this right.
万一有人需要,这里有一些虚拟代码,可以在按下按钮后打开模式窗口;我需要通过不小心单击背景或按esc来防止人们关闭它.
In case anyone needs it, here's a bit of dummy code that opens a modal window after a button press; I need to prevent people from closing it by accidentally clicking in the background or hitting esc.
library(shiny)
library(shinyBS)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
actionButton("go", "Go")
,bsModal("window", "Window", "go"
,textOutput("print"))
)
,mainPanel()
)
)
server <- function(input, output, session) {
output$print = renderText("This is a test")
}
shinyApp(ui, server)
我试图结合这两个线程中提供的解决方案:
I tried to combine the solutions provided in these two threads:
做这样的事情(以几种不同的组合),但这实际上没有用:
to do something like this (in a few different combinations), but that didn't really work:
actionButton("go", "Go")
,bsModal("window", "Window", "go"
,textOutput("print")
,tags$head(tags$style("#window .modal{backdrop: 'static'}")))
)
任何帮助将不胜感激!
推荐答案
这可以做到:
bsModalNoClose <-function(...) {
b = bsModal(...)
b[[2]]$`data-backdrop` = "static"
b[[2]]$`data-keyboard` = "false"
return(b)
}
然后您也可以关闭页眉和页脚,以防止在此处关闭:
And then you can close the header and footer as well, to prevent closing there:
bsModalNoClose("window", "Window", "go"
,textOutput("print"),
tags$head(tags$style("#window .modal-footer{display:none}
.modal-header{display:none}")))
这篇关于在Shiny应用程序中更改bsModal的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!