在Shiny中使用checkboxGroupInput时,如何添加标题和缩进复选框?

时间:2017-04-19 23:04:06

标签: r checkbox shiny

我想在我的复选框中添加标题并缩进复选框,因此它们看起来像这样:

Uppercase
  [] A
  [] B
  [] C
Lowercase
  [] a
  [] b
  [] c

这是我的代码

letters <- c("A","B","C","a","b","c")
library("shiny")
server <-function(input, output) {
    output$value <- renderPrint({ input$checkGroup })
}

ui <-fluidPage(
         checkboxGroupInput("checkGroup", 
                            label = h3("my letters"), 
                            choices = letters,
         fluidRow(column(3, verbatimTextOutput("value")))
)

runApp(list(ui = ui, server = server))

1 个答案:

答案 0 :(得分:0)

要缩进复选框,您可以设置左边距样式。

要拥有2个群组,您只需拆分数据并制作2 checkboxGroupInput s:

lletters <- c("a","b","c")
uletters <- c("A","B","C")
library("shiny")
server <-function(input, output) {
  checkGroup <- reactive(c(input$checkGroupL,input$checkGroupU))
  output$value <- renderPrint(checkGroup())
}

ui <-fluidPage( 
  tags$head(tags$style(HTML(".checkbox {margin-left:15px}"))),
  checkboxGroupInput("checkGroupL",
                     label = h3("Lower case"), 
                     choices = lletters),
  checkboxGroupInput("checkGroupU", 
                     label = h3("Upper case"), 
                     choices = uletters),
  fluidRow(column(3, verbatimTextOutput("value"))))

runApp(list(ui = ui, server = server))

enter image description here