首页 > 解决方案 > 更改一个 div 内两个 div 的背景颜色 R Shiny

问题描述

我想改变一个div里面有两个div的背景颜色。

我在 UI 中写过:

div(
       div(fileInput(inputId = "file1",
                     label = "File 1"),
           style="min-width:200px;max-width:45%; float:left; margin-right:2.5%;"),
                             
       div(fileInput(inputId = "file21",
                     label = "File 2,1"),
           fileInput(inputId = "file22",
                     label = "File 2,2"),
           style="min-width:200px;max-width:45%; float:left;"),
   style = "width: 100%; background-color:#ADD8E6;"),

但是颜色没有变化。当我将背景颜色更改为每个单独的颜色时,div它确实有效。但它看起来不太好。这就是为什么我想在更大的div.

任何想法?

也许他们是实现这一目标的另一种方式。

标签: htmlcssrshinyshinydashboard

解决方案


您需要给该父容器 div a或设置包含它的/height样式:fluidPagefluidRow

library(shiny)

ui <- fluidPage(
  div(
    div(fileInput(inputId = "file1",
                  label = "File 1"),
        style="min-width:200px;max-width:45%; float:left; margin-right:2.5%;"),
    
    div(fileInput(inputId = "file21",
                  label = "File 2,1"),
        fileInput(inputId = "file22",
                  label = "File 2,2"),
        style="min-width:200px;max-width:45%; float:left;"),
    # style = "width: 100%; background-color:#ADD8E6;") # height: 500px;
  ),
  style = "width: 100%; background-color:#ADD8E6;"
)

server <- function(input, output, session) {
  
}

shinyApp(ui, server)

推荐阅读