代码之家  ›  专栏  ›  技术社区  ›  agenis

渲染shinydashboard信息框。。。无shinydashboard

  •  7
  • agenis  · 技术社区  · 6 年前

    我在一个基于标准布局的闪亮应用程序上工作( fluidpage() ,我无法更改),我需要向用户显示一些反应性KPI 颜色、图标和文本 取决于一些计算的结果。此类信息的理想格式是 infoBox() 来自shinydashboard,如下所示:

    enter image description here

    当然,当我将此代码放在fluidpage中时,它会失去其样式:

    infoBox("Accuracy",  "50%",  icon = icon("ok", lib = "glyphicon"), color = "yellow")
    

    enter image description here

    我尝试的是:

    • 在我的fluidpage应用程序中添加一个仪表板页面,该页面可以工作,但我无法删除菜单、标题和其他相关内容。

    • 尝试自定义文本输出,这不是很好: enter image description here

    • 我不知道如何很好地添加glyphicon。

    您有什么解决方案可以实现吗? 谢谢

    1 回复  |  直到 6 年前
        1
  •  7
  •   Florian    6 年前

    您可以从 AdminLTE 并创建一个新的css文件。我复制了信息框组件的内容 bg-yellow 班请注意,为了使用其他颜色,您还必须复制相应的类,或者使用您自己的css为您的元素提供自定义颜色。

    为了制作一个有效的示例,我将CSS内联。当然,更简洁的解决方案是创建一个单独的CSS文件。如果您不熟悉如何操作,可以找到说明 here . 我希望这有帮助!

    library(shiny)
    library(shinydashboard)
    
    ui <- shinyUI(fluidPage(
      tags$head(
        tags$style(HTML("/*
     * Component: Info Box
                        * -------------------
                        */
                        .info-box {
                        display: block;
                        min-height: 90px;
                        background: #fff;
                        width: 100%;
                        box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
                        border-radius: 2px;
                        margin-bottom: 15px;
                        }
                        .info-box small {
                        font-size: 14px;
                        }
                        .info-box .progress {
                        background: rgba(0, 0, 0, 0.2);
                        margin: 5px -10px 5px -10px;
                        height: 2px;
                        }
                        .info-box .progress,
                        .info-box .progress .progress-bar {
                        border-radius: 0;
                        }
                        .info-box .progress .progress-bar {
                        background: #fff;
                        }
                        .info-box-icon {
                        border-top-left-radius: 2px;
                        border-top-right-radius: 0;
                        border-bottom-right-radius: 0;
                        border-bottom-left-radius: 2px;
                        display: block;
                        float: left;
                        height: 90px;
                        width: 90px;
                        text-align: center;
                        font-size: 45px;
                        line-height: 90px;
                        background: rgba(0, 0, 0, 0.2);
                        }
                        .info-box-icon > img {
                        max-width: 100%;
                        }
                        .info-box-content {
                        padding: 5px 10px;
                        margin-left: 90px;
                        }
                        .info-box-number {
                        display: block;
                        font-weight: bold;
                        font-size: 18px;
                        }
                        .progress-description,
                        .info-box-text {
                        display: block;
                        font-size: 14px;
                        white-space: nowrap;
                        overflow: hidden;
                        text-overflow: ellipsis;
                        }
                        .info-box-text {
                        text-transform: uppercase;
                        }
                        .info-box-more {
                        display: block;
                        }
                        .progress-description {
                        margin: 0;
                        }
    
                        .bg-yellow,
                        .callout.callout-warning,
                        .alert-warning,
                        .label-warning,
                        .modal-warning .modal-body {
                          background-color: #f39c12 !important;
                        }
    
                        "))
      ),
    
      headerPanel("New Application"),
    
      sidebarPanel(),
    
      mainPanel(
        infoBox("Accuracy",  "50%",  icon = icon("ok", lib = "glyphicon"), color = "yellow")
      )
    )
    )
    
    server <- function(input,output,session)
    {}
    
    shinyApp(ui,server)