我在 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/