发光的模式:宽度自动调整为内部内容

问题描述 投票:5回答:1

我正在尝试让我的模态根据内部内容调整其宽度。根据模式,我将有各种长度的按钮,我宁愿不为此格式化每个模式。

下面是我的代码:

library(shiny)
library (shinydashboard)

header <- dashboardHeader(title = "MRO Dash")
sidebar <- dashboardSidebar(actionButton("downloadBT", "Downloads", icon = icon("download")))

####FORMATTING MODAL HERE###
body <- dashboardBody(
  tags$head(tags$style("#test .modal-content {width: auto;}"))
  )
############################

ui <- dashboardPage(header, sidebar, body)

server <- function(input, output, session) {

  myModal <- function() {
    div(id = "test",
      modalDialog(downloadButton("download1","Download Shipments tonight let's go"),
                  br(),
                  br(),
                  downloadButton("download2","Download Shipments"),
                  easyClose = TRUE, footer = NULL)
    )
  }

  # open modal on button click
  observeEvent(input$downloadBT,
               ignoreNULL = TRUE,   # Show modal on start up
               showModal(myModal())
  )

  output$download1 <- downloadHandler(
    filename = function(){paste("MTD of SBU Shipments ",Sys.time(), ".csv", sep = "")},
    content = function(file){write.csv(, file, row.names = FALSE)}
  )

  output$download2 <- downloadHandler(
    filename = function(){paste("MTD of SBU Shipments ",Sys.time(), ".csv", sep = "")},
    content = function(file){write.csv(, file, row.names = FALSE)}
  )

}

shinyApp(ui, server)

对于模态,我知道我已经尝试了3个主要的类:

  • 。modal-dialog:扩展框以适合屏幕的整个宽度(如预期)

  • 。modal-content:不执行任何操作

  • 。modal-body:不执行任何操作

不确定为什么{width: auto;}对这两个类不起作用。

css shiny modal-dialog shinydashboard
1个回答
0
投票

我知道这很老了,但是偶然的机会是您没有弄清楚它,或者其他人正在寻找答案:

CSS:

.modal-dialog {
    width: fit-content !important;
}

将其硬编码到您的R闪亮应用中:

####FORMATTING MODAL HERE###
body <- dashboardBody(
  tags$head(tags$style("#test .modal-dialog {width: fit-content !important;}"))
  )
############################
© www.soinside.com 2019 - 2024. All rights reserved.