[英]Move R Shiny showNotification to center of screen
我正在考慮從 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 代碼包含在閃亮中。
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)
})
}
)
下面使用的應用程序模板是我從您提供的鏈接中的代碼中獲取的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.