繁体   English   中英

R Shiny:使用CSS作为checkboxInput

[英]R shiny: use css for checkboxInput

我以闪亮的形式发布了一个checkboxInput的简单示例(完整代码示例,这是我在ui.R中使用uiOutput的原因)。 但是我想使用css布局作为http://codepen.io/geedmo/pen/kBHsI/发布的复选框。 这将是我第一次在闪亮的应用程序中使用CSS的尝试,因此,对于在闪亮代码发布示例中的实现,我将不胜感激。

用户界面

library(shiny)

shinyUI(fluidPage(

  uiOutput("checkbox")

))

服务器

shinyServer(function(input, output) {

  output$checkbox <- renderUI({

   checkboxInput('checkboxid',
                 'Check me',
                 FALSE)

  })

})

我很好奇看到比我想出的解决方案更优雅的解决方案。 下面的代码实际上是该问题对http://codepen.io/geedmo/pen/kBHsI/的重构。 将已编译的css复制到style.css中,并将其放在www文件夹中。 修改了已编译的HTML,使其包含了闪亮工作所需的属性和标签。

这是代码:

    library(shiny)

    ui <- shinyUI(fluidPage(
            HTML("<link rel='stylesheet' type='text/css' href='style.css'>"),

       titlePanel("Checkboxgroup"),
       fluidRow(
       HTML(
               '<div id="checkGroup" class="form-group shiny-input-checkboxgroup shiny-input-container-inline">
                            <!--div class="shiny-options-group" -->
                                    <div class="btn-switch btn-switch-primary form-group">
                                            <input type="checkbox" id="input-btn-switch-primary" name="checkGroup" value="1"/>
                                            <label for="input-btn-switch-primary" class="btn btn-round btn-primary"><em class="glyphicon glyphicon-ok"></em><strong> CLICK ME</strong></label>
                                    </div>
                                    <div class="btn-switch btn-switch-success  form-group">
                                            <input type="checkbox" id="input-btn-switch-success" name="checkGroup" value="2"/>
                                            <label for="input-btn-switch-success" class="btn btn-round btn-success"><em class="glyphicon glyphicon-ok"></em><strong> CLICK ME</strong></label>
                                    </div>
                                    <div class="btn-switch btn-switch-info  form-group">
                                            <input type="checkbox" id="input-btn-switch-info" name="checkGroup" value="3"/>
                                            <label for="input-btn-switch-info" class="btn btn-round btn-info"><em class="glyphicon glyphicon-ok"></em><strong> CLICK ME</strong></label>
                                    </div>
                                    <div class="btn-switch btn-switch-warning  form-group">
                                            <input type="checkbox" id="input-btn-switch-warning" name="checkGroup" value="4"/>
                                            <label for="input-btn-switch-warning" class="btn btn-round btn-warning"><em class="glyphicon glyphicon-ok"></em><strong> CLICK ME</strong></label>
                                    </div>
                                    <div class="btn-switch btn-switch-danger  form-group">
                                            <input type="checkbox" id="input-btn-switch-danger" name="checkGroup" value="5"/>
                                            <label for="input-btn-switch-danger" class="btn btn-round btn-danger"><em class="glyphicon glyphicon-ok"></em><strong> CLICK ME</strong></label>
                                    </div>
                            <!-- /div -->
               </div>'
       ),
       textOutput("selectedOptions")
    )

    ))


    server <- shinyServer(function(input, output) {

       output$selectedOptions <- renderText({
          paste("Selected options:", paste((input$checkGroup), collapse = " "), sep = " ")
       })
    })


    shinyApp(ui = ui, server = server)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM