【发布时间】:2018-10-26 09:05:27
【问题描述】:
我正在开发一个闪亮的应用程序,我需要确保最终用户不会意外关闭 bsModal,因为上面有一些操作按钮。我做了一些研究并了解到我需要覆盖背景和键盘参数,但即使我已经看到了一些建议,我也不知道这需要在我的代码中的确切位置。我不精通 JavaScript,而且对 Shiny 还很陌生,所以即使这感觉像是一项简单的任务,我也做不到。
如果有人需要,这里有一段虚拟代码,可以在按下按钮后打开一个模式窗口;我需要防止人们通过不小心点击背景或按 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)
我尝试将这两个线程中提供的解决方案结合起来:
Is there a way to hide/disable the `Close` button on a `bsModal` window?
Prevent Bootstrap Modal from disappearing when clicking outside or pressing escape?
做这样的事情(在几个不同的组合中),但这并没有真正奏效:
actionButton("go", "Go")
,bsModal("window", "Window", "go"
,textOutput("print")
,tags$head(tags$style("#window .modal{backdrop: 'static'}")))
)
任何帮助将不胜感激!
【问题讨论】:
-
你试过this
-
@A.Suliman Brilliant,这对我来说应该可以达到目的!我仍然想知道是否有一个逻辑可以通过 ShinyBS 实现,因为我将来可能需要对模态进行其他调整。