我正在尝试实现以下switchInput外观:
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
tags$head(tags$style(HTML('.bootstrap-switch .bootstrap-switch-handle-off.bootstrap-switch-success,
.bootstrap-switch .bootstrap-switch-handle-on.bootstrap-switch-success {
background: #1ee38d;
}'))),
#switchInput color while off
tags$head(tags$style(HTML('.bootstrap-switch .bootstrap-switch-handle-off.bootstrap-switch-warning,
.bootstrap-switch .bootstrap-switch-handle-on.bootstrap-switch-warning {
background: #00bfff;
}'))),
switchInput(inputId = "ans_1", value = TRUE,
onLabel = "T", onStatus = "success", offStatus = "warning",
offLabel = "F")
)
server <- function(input, output, session) {
}
shinyApp(ui, server)然而,我试图通过renderUI和uiOutput这样做是不成功的。
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
tags$head(tags$style(HTML('.bootstrap-switch .bootstrap-switch-handle-off.bootstrap-switch-success,
.bootstrap-switch .bootstrap-switch-handle-on.bootstrap-switch-success {
background: #1ee38d;
}'))),
#switchInput color while off
tags$head(tags$style(HTML('.bootstrap-switch .bootstrap-switch-handle-off.bootstrap-switch-warning,
.bootstrap-switch .bootstrap-switch-handle-on.bootstrap-switch-warning {
background: #00bfff;
}'))),
uiOutput("ex1")
)
server <- function(input, output, session) {
output$ex1 = renderUI({
switchInput(inputId = "ans_1", value = TRUE,
onLabel = "T", onStatus = "success", offStatus = "warning",
offLabel = "F")})
}
shinyApp(ui, server)帮助欣赏通过renderUI来促进它的工作。谢谢
发布于 2021-06-17 17:33:31
下面是另一种解决方案,使用设置为200的width选项。还保存您的CSS样式,包括在一个tagList。
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
tags$head(tags$style(HTML('.bootstrap-switch .bootstrap-switch-handle-off.bootstrap-switch-success,
.bootstrap-switch .bootstrap-switch-handle-on.bootstrap-switch-success {
background: #1ee38d;
}'))),
#switchInput color while off
tags$head(tags$style(HTML('.bootstrap-switch .bootstrap-switch-handle-off.bootstrap-switch-warning,
.bootstrap-switch .bootstrap-switch-handle-on.bootstrap-switch-warning {
background: #00bfff;
}'))),
uiOutput("ex1")
)
server <- function(input, output, session) {
output$ex1 <- renderUI({
tagList(tags$head(tags$style(HTML('.bootstrap-switch .bootstrap-switch-handle-off.bootstrap-switch-success,
.bootstrap-switch .bootstrap-switch-handle-on.bootstrap-switch-success {
background: #1ee38d;
}'))),
#switchInput color while off
tags$head(tags$style(HTML('.bootstrap-switch .bootstrap-switch-handle-off.bootstrap-switch-warning,
.bootstrap-switch .bootstrap-switch-handle-on.bootstrap-switch-warning {
background: #00bfff;
}'))),
switchInput(inputId = "ans_1", value = TRUE,
onLabel = "T", onStatus = "success", offStatus = "warning",
offLabel = "F", width="200px"))})
}
shinyApp(ui, server)https://stackoverflow.com/questions/68023801
复制相似问题