A_Skelton73
A_Skelton73

Reputation: 1190

R Shiny Wrapping UI elements

Is there any way to wrap UI elements? I've got a checkboxGroupInput and I'd like to wrap the elements so they fit into the whole wellPanel?

EDIT: Reproducible Example added Below.

Where the checkboxes list in the wellPanel, I'd like a way to wrap it to the width of the wallPanel, so that it saves space and creates a better layout. Any suggestions?

global.R

library(shiny)
library(shinyIncubator)
data_in <- c(1:50)

ui.R

library(shiny)
library(shinyIncubator)

shinyUI(fluidPage(
  fluidRow(
    headerPanel('Test Page')
  ),
  fluidRow(
    plotOutput('plot')
  ),
  fluidRow(
    wellPanel(uiOutput("checkbGroups"))
  )
))

server.R

shinyServer(function(input, output) {
  values <- reactiveValues()

  datasetInput <- reactive({
    values$data <- input$foo
  })

  plotInput <- reactive({
    datasetInput()
    plot(x=values$data, y=values$data, col=values$data)
  })

  output$checkbGroups <- renderUI({
    checkboxGroupInput(inputId = 'foo', label = 'Numbers To use', 
                       choices = data_in, 
                       selected = data_in)
  })

  output$plot <- renderPlot({
    plotInput()
  })
})

Upvotes: 2

Views: 1647

Answers (1)

jdharrison
jdharrison

Reputation: 30425

You can add some styling on your checkboxes

library(shiny)
library(shinyIncubator)
data_in <- c(1:50)

runApp(
  list(ui = fluidPage(
    fluidRow(headerPanel('Test Page')),
    fluidRow(plotOutput('plot')),
    fluidRow(wellPanel(uiOutput("checkbGroups")))
  ),
  server = function(input, output) {
    values <- reactiveValues() 
    datasetInput <- reactive({
      values$data <- input$foo
    })
    plotInput <- reactive({
      datasetInput()
      plot(x=values$data, y=values$data, col=values$data)
    })
    output$checkbGroups <- renderUI({
      test <- checkboxGroupInput(inputId = 'foo', label = 'Numbers To use', 
                         choices = data_in, 
                         selected = data_in)
      gsub("class=\"checkbox\"", "class=\"checkbox\" style=\"float:left; margin:25px;\"", test)
    })
    output$plot <- renderPlot({plotInput()})
  })
)

enter image description here

Upvotes: 2

Related Questions