gpt4 book ai didi

css - Shiny 的模态 : Having width adjust automatically to content inside

转载 作者:行者123 更新时间:2023-12-03 14:39:06 25 4
gpt4 key购买 nike

我试图让我的模态根据里面的内容调整它的宽度。根据模态,我会有各种长度的按钮,我宁愿不为此格式化每个模态。

下面是我的代码:

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;}不适用于 2 个类(class)。

    最佳答案

    我知道这已经过时了,但如果您没有弄清楚或其他人正在寻找答案,那是不可能的:

    CSS:

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

    将其硬编码到您的 R Shiny 应用程序中:
    ####FORMATTING MODAL HERE###
    body <- dashboardBody(
    tags$head(tags$style("#test .modal-dialog {width: fit-content !important;}"))
    )
    ############################

    关于css - Shiny 的模态 : Having width adjust automatically to content inside,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52743315/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com