我使用下面的代码创建了一组checkboxGroupInput,但显示不正确。
看起来像这样:

知道如何在Shiny中强制正确对齐吗?

用户界面

uiOutput(outputId = "numSelector")

服务器
        output$numSelector <- renderUI({
        out <- checkboxGroupInput(
            inputId = "numSelector",
            label   = "Select the numbers to filter on:",
            choices = selectRange(input$dataName),
            inline = TRUE
        )
        return(out)
    })

最佳答案

通过调整div标签可以解决此问题。一个小小的 Shiny 应用程序示例:

library(shiny)

# tweaks, a list object to set up multicols for checkboxGroupInput
tweaks <-
  list(tags$head(tags$style(HTML("
                                 .multicol {
                                   height: 150px;
                                   -webkit-column-count: 5; /* Chrome, Safari, Opera */
                                   -moz-column-count: 5;    /* Firefox */
                                   column-count: 5;
                                   -moz-column-fill: auto;
                                   -column-fill: auto;
                                 }
                                 "))
                                 ))

# values to show, or not show, these will be the 'choices' and 'selected' values
# for the checkboxGroupInput()
all_rows <- 1:25
names(all_rows) <- paste("Row", all_rows)

# data control: the checkboxes will control the data values plotted
controls <-
  list(h3("Multicolumn checkboxGroupInput"),
       tags$div(align = 'left',
                class = 'multicol',
                checkboxGroupInput(inputId  = 'numSelector',
                                   label    = "Select the numbers:",
                                   choices  = all_rows,
                                   selected = all_rows,
                                   inline   = FALSE)))

# run the app
runApp(list(
            ui = fluidPage(tweaks,
                           fluidRow(column(width = 4, controls),
                                    column(width = 8, plotOutput("plot")))),
            server = function(input, output) {
              plot_data <- reactive(input$numSelector)

              output$plot <- renderPlot(plot(x = plot_data(),
                                             y = plot_data(),
                                             pch = 6,
                                             cex = 2,
                                             xlim = c(1, 25),
                                             ylim = c(1, 25)))
            }))
checkboxGroupInput看起来像这样:

r - 如何在R Shiny中对齐一组checkboxGroupInput-LMLPHP

我将这个解决方案与帮助表一起拼凑而成:CSS-TricksThis Google Groups post。

关于r - 如何在R Shiny中对齐一组checkboxGroupInput,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29738975/

10-11 16:11