【问题标题】:R shiny using css with modal dialogR闪亮使用带有模态对话框的css
【发布时间】:2020-10-01 08:06:35
【问题描述】:

我想在使用某种 css 样式的 R 闪亮应用程序中使用模式对话框。我可以使用没有 css 样式的模态对话框,也可以使用没有模态对话框的 css 样式。但是,如果我尝试同时运行模态对话框和 css 样式,模态对话框将不再显示。

以下代码可用于重现我的结果。我的 css 样式表完全来自 https://bootswatch.com/,它需要保存在一个名为 www 的子目录中。要查看各种结果,请评论和取消评论 theme = "bootstrap-flatly.css" 行:

shinyApp(ui=fluidPage(
  theme = "bootstrap-flatly.css",
  h1("Heading"),
  div("Some text"),
  selectInput("selectInput", "SomeInput", c(1,2,3),selected = NA, multiple = TRUE),
  actionButton("print","print")
),
server <- function(input,output){
  showModal(modalDialog(
    title = "My message",
    easyClose = FALSE,
    footer = actionButton("closemodal", "OK")
  ))
  observeEvent(
    {
      input$closemodal
    },{
      removeModal()})
  observeEvent(input$print, reactiveValuesToList(input) %>% print)
}
)

谁能解释这种行为并提示我如何让 css 样式与我的模态对话框一起使用?

【问题讨论】:

    标签: css r shiny modal-dialog


    【解决方案1】:

    here 提到了这个问题,但我无法将解决方案应用于您的情况(我尝试修改 css 文件以包含 .modal {z-index: 1050;} 但没有成功)。

    另一种方法是使用shinythemes 包,它提供flatly 主题,无需下载任何内容。

    library(shiny)
    library(shinythemes)
    
    shinyApp(ui=fluidPage(
      theme = shinytheme("flatly"),
      h1("Heading"),
      div("Some text"),
      selectInput("selectInput", "SomeInput", c(1,2,3),selected = NA, multiple = TRUE),
      actionButton("print","print")
    ),
    server <- function(input,output){
    
      showModal(modalDialog(
        title = "My message",
        easyClose = FALSE,
        footer = actionButton("closemodal", "OK")
      ))
    
      observeEvent(
        {
          input$closemodal
        },{
          removeModal()})
      observeEvent(input$print, reactiveValuesToList(input) %>% print)
    }
    )
    

    【讨论】:

      猜你喜欢
      • 2021-11-23
      • 2021-08-03
      • 1970-01-01
      • 2019-05-11
      • 1970-01-01
      • 2014-08-26
      • 2018-08-14
      • 2017-02-16
      • 1970-01-01
      相关资源
      最近更新 更多