有没有办法改变警告消息的字体大小以及
shinyFeedback
中图标所占用的空间?在我的 shiny
应用程序中,我为 textInput
定义了绝对宽度,当触发警告消息时,即使我将其设置为 icon=NULL
,图标也会占用空间,从而切断输入。另外,我真的很想让警告消息更小。有没有办法通过css
中的tags$head(tags$style())
来做到这一点?
最小可重现示例:
library(shiny)
library(shinyFeedback)
ui<-shinyUI(fluidPage(
shinyFeedback::useShinyFeedback(),
textInput("time", "Timestamp",
value = '2024/04/01 00:00:00',
width = '160px', placeholder = NULL)
))
server<- function(input, output, session) {
observe(shinyFeedback::feedbackWarning("time",
!(grepl('[0-9]{4}/[0-9]{2}/[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}', input$time)),
"Please use a valid timeformat",
icon=NULL))
}
shinyApp(ui,server)
我不明白你所说的“图标”是什么意思,所以提供更多信息会更好。
无论如何,你可以像你提到的那样用CSS更改shinyfeedback的文本大小。
见下文(
server
相同)
ui <- shinyUI(fluidPage(
shinyFeedback::useShinyFeedback(),
tags$head(
tags$style(HTML("
#time-text > p { # shinyfeedback's text with id = time
font-size: 10px;
}
"))
),
textInput("time", "Timestamp",
value = "2024/04/01 00:00:00",
width = "160px", placeholder = NULL
)
))