【发布时间】:2021-09-02 12:29:53
【问题描述】:
我正在尝试拥有以下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 促进它的工作。谢谢
【问题讨论】:
标签: css r twitter-bootstrap shiny