Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R Shiny: Side by Side Checkbox

Tags:

r

shiny

I was wondering if its possible to display the check box option side by side on the UI. Some sample code that I've tried:

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;

))
like image 303
user1234440 Avatar asked Jun 24 '13 13:06

user1234440


2 Answers

Try fudging some bootstrap syntax:

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 for horizontal radio button

from ?radiobutton

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

replace with a

 gsub("label class=\"radio\"", "label class=\"radio inline\"",radioButtons("dist", "Distribution type:",
             c("Normal" = "norm",
               "Uniform" = "unif",
               "Log-normal" = "lnorm",
               "Exponential" = "exp")))
  )
like image 102
user1609452 Avatar answered Oct 04 '22 11:10

user1609452


You can use checkboxGroupInput with inline = TRUE param:

checkboxGroupInput(inputId = "simOption", label = "",
                   choices = c("Historical Data" = TRUE,
                               "Historical Data 2" = TRUE),
                   inline = TRUE)
like image 31
Artem Klevtsov Avatar answered Oct 04 '22 11:10

Artem Klevtsov