【问题标题】:Multiple colourpickers within splitLayout, colour box gets hiddensplitLayout 中的多个颜色选择器,颜色框被隐藏
【发布时间】:2018-08-07 05:48:26
【问题描述】:

当使用 splitLayout 并排使用两个颜色选择器时,颜色映射会被隐藏。使用tags$style...HTML() 可以轻松修复它,有什么想法吗?

这是一个例子:

library(shiny)
library(colourpicker)

shinyApp(
  ui = fluidPage(
    sidebarPanel(
      splitLayout(
        colourInput("PlotThemeColour1",
                    "Plot theme shade 1",
                    "#C2C2C2"),
        colourInput("PlotThemeColour2",
                    "Plot theme shade 2",
                    "#E5E5E5"))),
    mainPanel(textOutput("myCols"))
  ),

  server = function(input, output, session) {
    output$myCols <- renderText({
      paste(input$PlotThemeColour1, "and", input$PlotThemeColour2)

    })
  })

输出

【问题讨论】:

    标签: r colors shiny


    【解决方案1】:

    我不确定修复它的正确方法是什么。但是一个快速的解决方法是覆盖导致它的 css。目前,该 css .shiny-split-layout&gt;divoverflow 的值设置为 auto 并且存在于 shiny.css 中,因此使用内联 css 用 overflow:visible 覆盖它似乎可以解决问题。

    library(shiny)
    library(colourpicker)
    
    shinyApp(
      ui = fluidPage(
         tags$style(HTML('.shiny-split-layout>div {
                             overflow:visible;
                                       }')), 
        sidebarPanel(
          splitLayout(
            colourInput("PlotThemeColour1",
                        "Plot theme shade 1",
                        "#C2C2C2"),
            colourInput("PlotThemeColour2",
                        "Plot theme shade 2",
                        "#E5E5E5"))),
        mainPanel(textOutput("myCols"))
      ),
    
      server = function(input, output, session) {
        output$myCols <- renderText({
          paste(input$PlotThemeColour1, "and", input$PlotThemeColour2)
    
        })
      })
    

    方法 #2:

    使用cellArgs of splitLayout 覆盖单个单元格css。

    library(shiny)
    library(colourpicker)
    
    shinyApp(
      ui = fluidPage(
    
        sidebarPanel(
          splitLayout(
            colourInput("PlotThemeColour1",
                        "Plot theme shade 1",
                        "#C2C2C2"),
            colourInput("PlotThemeColour2",
                        "Plot theme shade 2",
                        "#E5E5E5"), cellArgs = list (style = "overflow:visible"))),
        mainPanel(textOutput("myCols"))
        ),
    
      server = function(input, output, session) {
        output$myCols <- renderText({
          paste(input$PlotThemeColour1, "and", input$PlotThemeColour2)
    
        })
      })
    

    【讨论】:

    • 谢谢你,这是我所希望的。如果有其他方法可以在不使用tags$ 的情况下实现此目的,我将保持开放状态。
    • @zx8754 很高兴能帮上忙。还添加了第二种方法。
    • 太好了,cellArgs 是我的最佳选择。谢谢。
    【解决方案2】:

    splitLayoutcellArgs 可以容纳你的溢出:

    library(shiny)
    library(colourpicker)
    
    shinyApp(
      ui = fluidPage(
        sidebarPanel(
          splitLayout(cellArgs = list(style = "overflow: visible;"),
            colourInput("PlotThemeColour1",
                        "Plot theme shade 1",
                        "#C2C2C2"),
            colourInput("PlotThemeColour2",
                        "Plot theme shade 2",
                        "#E5E5E5"))),
        mainPanel(textOutput("myCols"))
      ),
    
      server = function(input, output, session) {
        output$myCols <- renderText({
          paste(input$PlotThemeColour1, "and", input$PlotThemeColour2)
    
        })
      })
    

    【讨论】:

    • 抱歉在发布我的方法 #2 之前没有看到您的答案
    • 是的,谢谢,cellArgs 是我正在寻找的,按预期工作。
    猜你喜欢
    • 2011-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-19
    • 1970-01-01
    • 1970-01-01
    • 2014-12-17
    相关资源
    最近更新 更多