首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >R闪亮: RenderUI of switchInput未显示

R闪亮: RenderUI of switchInput未显示
EN

Stack Overflow用户
提问于 2021-06-17 17:11:39
回答 1查看 162关注 0票数 0

我正在尝试实现以下switchInput外观:

代码语言:javascript
复制
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)

然而,我试图通过renderUIuiOutput这样做是不成功的。

代码语言:javascript
复制
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来促进它的工作。谢谢

EN

回答 1

Stack Overflow用户

发布于 2021-06-17 17:33:31

下面是另一种解决方案,使用设置为200的width选项。还保存您的CSS样式,包括在一个tagList

代码语言:javascript
复制
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)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68023801

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档