gpt4 book ai didi

css - 将 R Shiny showNotification 移动到屏幕中央

转载 作者:技术小花猫 更新时间:2023-10-29 11:06:05 25 4
gpt4 key购买 nike

我正在考虑自定义 Shiny 的 showNotification() 功能。

https://gallery.shinyapps.io/116-notifications/

我希望在屏幕中间而不是右下角生成消息。我不认为这可以本地设置,但我希望有人能就如何实现这一点提出建议。

最佳答案

您可以使用 tags$style 覆盖 CSS 类属性(在本例中为:.shiny-notification)。您还可以使用该方法调整宽度和高度等其他属性。

css 部分将是:

.shiny-notification {
position:fixed;
top: calc(50%);
left: calc(50%);
}

将通知设置为屏幕宽度的 50% 和高度宽度的 50%。

您可以在 ui 函数中使用以下代码,将 css 代码包含在 shiny 中。

tags$head(
tags$style(
HTML(CSS-CODE....)
)
)

完整的可复制应用如下:

library(shiny)

shinyApp(
ui = fluidPage(
tags$head(
tags$style(
HTML(".shiny-notification {
position:fixed;
top: calc(50%);
left: calc(50%);
}
"
)
)
),
textInput("txt", "Content", "Text of message"),
radioButtons("duration", "Seconds before fading out",
choices = c("2", "5", "10", "Never"),
inline = TRUE
),
radioButtons("type", "Type",
choices = c("default", "message", "warning", "error"),
inline = TRUE
),
checkboxInput("close", "Close button?", TRUE),
actionButton("show", "Show"),
actionButton("remove", "Remove most recent")
),
server = function(input, output) {
id <- NULL

observeEvent(input$show, {
if (input$duration == "Never")
duration <- NA
else
duration <- as.numeric(input$duration)

type <- input$type
if (is.null(type)) type <- NULL

id <<- showNotification(
input$txt,
duration = duration,
closeButton = input$close,
type = type
)
})

observeEvent(input$remove, {
removeNotification(id)
})
}
)

下面使用的应用程序模板是我从您提供的链接中的代码中获取的。

关于css - 将 R Shiny showNotification 移动到屏幕中央,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44112000/

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