2013-06-24 42 views
11

Tôi đã tự hỏi liệu có thể hiển thị tùy chọn hộp kiểm cạnh nhau trên giao diện người dùng hay không. Một số mẫu mã mà tôi đã cố gắng:R Shiny: Side by Side Checkbox

shinyUI(pageWithSidebar(
    headerPanel("Example"), 
    sidebarPanel( 
    checkboxInput(inputId = "simOption", label = "Historical Data",value=TRUE), 
    checkboxInput(inputId = "simOption2", label = "Historical Data 2",value=TRUE) 


), 

    mainPanel(
tabsetPanel(

    tabPanel("Heatmap", 
      plotOutput("temp") 
), 
    tabPanel("About"), 

    id="tabs" 
)#tabsetPanel 

)#mainPane; 

)) 

Trả lời

13

Hãy thử fudging một số cú pháp bootstrap:

shinyUI(pageWithSidebar(
    headerPanel("Example"), 
    sidebarPanel( 

    withTags(div(class='row-fluid', 
       div(class='span3', checkboxInput(inputId = "simOption", label = "Historical Data",value=TRUE)), 
       div(class='span5', checkboxInput(inputId = "simOption2", label = "Historical Data 2",value=TRUE)) 
    )) 



), 

    mainPanel(
tabsetPanel(

    tabPanel("Heatmap", 
      plotOutput("temp") 
), 
    tabPanel("About"), 

    id="tabs" 
)#tabsetPanel 

)#mainPane; 

)) 

https://medium.com/what-i-learned-building/99fdd6e46586

EDIT cho nút radio ngang

từ ?radiobutton

radioButtons("dist", "Distribution type:", 
      c("Normal" = "norm", 
       "Uniform" = "unif", 
       "Log-normal" = "lnorm", 
       "Exponential" = "exp")) 

thay thế với một

gsub("label class=\"radio\"", "label class=\"radio inline\"",radioButtons("dist", "Distribution type:", 
      c("Normal" = "norm", 
       "Uniform" = "unif", 
       "Log-normal" = "lnorm", 
       "Exponential" = "exp"))) 
) 
+0

Tôi mới vào bootstrap, nhưng những gì nếu nó là một nút radio trong sáng bóng? Làm thế nào bạn có thể áp dụng các khuôn khổ trên? Nút radio là khá phức tạp hơn như một chức năng duy nhất của nó như trái ngược với hai cái riêng biệt. Cảm ơn, – user1234440

+0

https://github.com/plataformatec/simple_form/issues/649 ám chỉ đến những gì bạn đang mô tả. Bạn chỉ có thể xây dựng quyền kiểm soát của riêng mình bằng cách sử dụng các khối xây dựng thẻ cơ bản. – user1609452

+0

Trừ khi bạn rất lười biếng như tôi trong trường hợp bạn có thể 'gsub' – user1609452

13

Bạn có thể sử dụng checkboxGroupInput với inline = TRUE param:

checkboxGroupInput(inputId = "simOption", label = "", 
        choices = c("Historical Data" = TRUE, 
           "Historical Data 2" = TRUE), 
        inline = TRUE) 
Các vấn đề liên quan