【问题标题】:Fluid row issue with a checkbox input in ShinyShiny中复选框输入的流动行问题
【发布时间】:2018-04-15 14:53:17
【问题描述】:

我在格式化一行动态输入时遇到问题。每当我将 checkboxInput 作为fluidRow 的一部分时,它都会跳转到新行,而不是将操作按钮直接放在复选框的右侧。知道我做错了什么吗?

这是当前代码:

  #Dynamic UI based on how many cohorts exist;
  cohort_ui = eventReactive(c(input$save_cohort, input$reset_cohorts, input$delete_cohort1, input$delete_cohort2), {
    bootstrapPage(
      strong("Combine Cohorts"),
      lapply(1:length(names(cohorts)), function(i) {
        fluidRow(column(width = 12, checkboxInput(paste0("active_cohort",i), label = names(cohorts)[i], value = FALSE), 
                        actionButton(paste0("delete_cohort",i), "Delete"), actionButton(paste0("rename_cohort",i), "Rename"), 
                        textInputRow(paste0("rename_cohort_text",i), label= NULL, placeholder = "Enter new cohort name")))
      }),
      radioButtons("join_cohorts", label = "Join Operation", choices = c("Union", "Intersection", "Difference"), selected = NULL),
      textInput("join_cohorts_name", label = "New Cohort Name", value = "", width = NULL, placeholder = NULL),
      actionButton("join_cohorts_save", "Save")
    )
  })
  output$cohort_ui = renderUI({cohort_ui()})

【问题讨论】:

    标签: r user-interface shiny


    【解决方案1】:

    这是因为复选框是块级元素。您需要添加 css 以使其内联。简短的例子:

    library(shiny)
    
    mycss <- "
    .mycheckbox .shiny-input-container {
      display: inline-block;
      width: auto;
    }
    "
    
    ui <- fluidPage(
      tags$style(mycss),
      span(class="mycheckbox", checkboxInput("checkbox", "checkbox")),
      actionButton("button", "button")
    )
    
    server <- function(input, output, session) {}
    
    shinyApp(ui, server)
    

    【讨论】:

    • 谢谢!从未听说过块级元素,但它是有道理的。
    猜你喜欢
    • 1970-01-01
    • 2016-06-14
    • 1970-01-01
    • 2019-01-29
    • 1970-01-01
    • 2011-05-15
    • 1970-01-01
    • 2017-05-31
    • 2013-11-05
    相关资源
    最近更新 更多