html - R Shiny : use css for checkboxInput

标签 html css r shiny

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

ui.R

library(shiny)

shinyUI(fluidPage(

  uiOutput("checkbox")

))

服务器.R

shinyServer(function(input, output) {

  output$checkbox <- renderUI({

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

  })

})

最佳答案

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

这是代码:

    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)

关于html - R Shiny : use css for checkboxInput,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39925148/

相关文章:

javascript - 如何到达 div 的顶部但不使用 jQuery 滚动?

html - Safari 浏览器中的内联 block 故障

jquery - Bootstrap 轮播 - 移动触摸问题

html - 一行上传文件

Jquery隐藏/显示div但也保留来自 "hiding"的切换链接

r - spaCy 或语言模型 en_core_web_sm 未安装在任何 python 可执行文件中

r - 提升值计算

html - 在不同浏览器上检查网页外观的方法

html - 如何在 firefox 和其他不支持 html5 标签选项的浏览器中获取占位符文本?

python - 如何有效地将 python pandas 数据框保存在 hdf5 中并在 R 中将其作为数据框打开?