【问题标题】:Modal Dialog in Shiny: Can adjust width but not heightShiny中的模态对话框:可以调整宽度但不能调整高度
【发布时间】:2018-01-14 19:37:01
【问题描述】:

在我的 Shiny 应用程序中,我有几个来自 shinyBS 包的模式窗口。我可以像这样调整这些模态窗口的宽度:

tags$head(tags$style(HTML('

                                                  .modal-lg {
                                                  width: 1200px;
                                                  }
                                                  #abs_1 {background-color: white;;}
                                                  #clear{background-color: turquoise3;;}
                                                  #disease{background-color: turquoise3;;}
                                                  #bleach{background-color: turquoise3;;}
                                                  #regionSelect{background-color: turquoise3;;}
                                                  #yearSelect{background-color: turquoise3;;}
                                                  #speciesSelect{background-color: turquoise3;;}
                                                  ')))

改变宽度参数中的像素数会改变模态窗口的宽度。但是,如果我使用高度而不是宽度,则更改像素数对模态窗口的高度没有影响。为什么会这样?

【问题讨论】:

标签: css r shiny modal-dialog


【解决方案1】:

您想修改模态体的高度。试试这个:

library(shiny)
library(shinyBS)
shinyApp(
  ui = basicPage(
    actionButton("show", "Show modal dialog"),
    tags$head(tags$style(".modal-dialog{ width:1000px}")),
    tags$head(tags$style(".modal-body{ min-height:700px}")),
    bsModal('boxPopUp', 'Test','test')


  ),
  server = function(input, output,session) {
    observeEvent(input$show, {
      toggleModal(session, "boxPopUp", toggle = "toggle")
    })
  }
)

编辑:在下面回答马克的评论

是的,您可以为此使用 bsModal 的 id,见下文。例如,第一个样式标签现在适用于所有 .modal-dialog 类的 div,它们位于 id 为 boxPopUp1 的 div 中

library(shiny)
library(shinyBS)
shinyApp(
  ui = basicPage(
    actionButton("show1", "Show modal dialog"),
    actionButton("show2", "Show modal dialog"),
    tags$head(tags$style("#boxPopUp1 .modal-dialog{ width:1000px}")),
    tags$head(tags$style("#boxPopUp1 .modal-body{ min-height:700px}")),
    tags$head(tags$style("#boxPopUp2 .modal-dialog{ width:100px}")),
    tags$head(tags$style("#boxPopUp2 .modal-body{ min-height:100px}")),
    bsModal('boxPopUp1', 'Big','test'),
    bsModal('boxPopUp2', 'Small','test')


  ),
  server = function(input, output,session) {
    observeEvent(input$show1, {
      toggleModal(session, "boxPopUp1", toggle = "toggle")
    })
    observeEvent(input$show2, {
      toggleModal(session, "boxPopUp2", toggle = "toggle")
    })
  }
)

【讨论】:

  • 弗洛里安,在我花费大量时间构建演示应用程序和问题之前,您是否会碰巧知道如何将样式标签应用于闪亮的单个 .modal-dialogs,例如其中 2 个并且您想为它们设置不同的样式?
  • 弗洛里安,我可以通过linkedin等直接联系你吗?我有一些后续行动更多的是讨论而不是评论。 (顺便说一下,这个 SO 问题不是我的,但与我正在寻找的类似)
  • 嗨,马克,没关系,您可以在我的个人资料中找到我的linkedIn 和电子邮件。
  • 你好弗洛里安。即使在 3 年后,这也是非常有用的。我们如何用闪亮的正版modalDialog() 做同样的事情?我试图指定一个 id 没有任何成功。
猜你喜欢
  • 2019-01-27
  • 2020-10-20
  • 2020-07-10
  • 1970-01-01
  • 1970-01-01
  • 2021-10-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多