【问题标题】:not able to add text boxes on top of valueBox() in r flexdashboard无法在 r flexdashboard 中的 valueBox() 顶部添加文本框
【发布时间】:2022-01-07 20:12:20
【问题描述】:

有时很难弄清楚如何将 flexdashboard 用于最大目的。 由于可用的文件不多,我有时会寻求其他人的帮助。

我有如下代码所示的 flexdashboard 设计:

---
title: "My Design"
output:
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: fill

runtime: shiny
---

```{css}
.value-box {
  height: 110px;
}

```


```{r global, echo = FALSE}
library(shiny)
library(flexdashboard)

vb1 <- valueBox(value = tags$p(paste(100, "%"), style = "font-size: 140%;"),
         caption = tags$p("My Value Box 1", 
                       style = "background-color:rgba(39, 128, 227, 0.0); 
                       border-color:rgba(39, 128, 227, 0.0); 
                       position: absolute; 
                       overflow: hidden; 
                       left: 5%; top: 1px; 
                       right: 0px; 
                       bottom: 0px; width:100%"),
    icon = "fa-thumbs-up",
    color = "success" )


vb2 <- valueBox(value = tags$p(paste(50, "%"), style = "font-size: 140%;"),
         caption = tags$p("My Value Box 2", 
                       style = "background-color:rgba(39, 128, 227, 0.0); 
                       border-color:rgba(39, 128, 227, 0.0); 
                       position: absolute; 
                       overflow: hidden; 
                       left: 5%; top: 1px; 
                       right: 0px; 
                       bottom: 0px; width:100%"), 
         icon = "fa-hourglass-end", color = "danger")

vb3 <- valueBox(value = tags$p(paste(80, "%"), style = "font-size: 140%;"),
         caption = tags$p("My Value Box 3", 
                       style = "background-color:rgba(39, 128, 227, 0.0); 
                       border-color:rgba(39, 128, 227, 0.0); 
                       position: absolute; 
                       overflow: hidden; 
                       left: 5%; top: 1px; 
                       right: 0px; 
                       bottom: 0px; width:100%"),
         icon = "fa-eur", color = "warning")

vb4 <- valueBox(value = tags$p(paste(100, "%"), style = "font-size: 140%;"),
         caption = tags$p("My Value Box 4", 
                       style = "background-color:rgba(39, 128, 227, 0.0); 
                       border-color:rgba(39, 128, 227, 0.0); 
                       position: absolute; 
                       overflow: hidden; 
                       left: 5%; top: 1px; 
                       right: 0px; 
                       bottom: 0px; width:100%"),
         icon = "fa-clock", color = "success")

```


My Dashboard {data-icon="fa-search"}
=======================================================================

## Row {.sidebar data-width=280 data-padding=10}

```{r}

tags$h4('My Side Bar')
tags$hr()

```


Row 
-----------------------------------------------------------------------

### {.value-box}

```{r}

renderValueBox(vb1)

```


###  {.value-box}

```{r}

renderValueBox(vb2)

```


###  {.value-box}

```{r}

renderValueBox(vb3)

```

###  {.value-box}

```{r}

renderValueBox(vb4)

```

我想在数值框上添加文本框(如下图黑色部分)。

怎么做?

【问题讨论】:

    标签: r shiny flexdashboard


    【解决方案1】:

    这是你想要的吗?

    ---
    title: "My Design"
    output:
      flexdashboard::flex_dashboard:
        orientation: rows
        vertical_layout: fill
    
    runtime: shiny
    ---
    
    ```{css}
    .value-box {
      height: 110px;
    }
    
    ```
    
    
    ```{r global, echo = FALSE}
    library(shiny)
    library(flexdashboard)
    top_text_style <- 
    "background-color:rgba(39, 128, 227, 0.0); 
    border-color:rgba(39, 128, 227, 0.0); 
    position: absolute; 
    overflow: hidden; 
    left: 5%; top: 1px; 
    right: 0px; 
    bottom: 0px; width:100%"
    bottom_text_style <- 
    "position: absolute;
    bottom: 0;
    left: 5px;
    font-weight: 600;"
    
    vb1 <- valueBox(
        value = tags$p(paste(100, "%"), style = "font-size: 140%;"),
         caption = div(
             tags$p("My Value Box 1", style = top_text_style), 
             tags$h4("some text1", style = bottom_text_style)
          ),
         icon = "fa-thumbs-up", color = "success" 
    )
    
    
    vb2 <- valueBox(
        value = tags$p(paste(100, "%"), style = "font-size: 140%;"),
         caption = div(
             tags$p("My Value Box 2", style = top_text_style), 
             tags$h4("some text2", style = bottom_text_style)
          ),
         icon = "fa-hourglass-end", color = "danger"
    )
    
    vb3 <- valueBox(
        value = tags$p(paste(100, "%"), style = "font-size: 140%;"),
         caption = div(
             tags$p("My Value Box 3", style = top_text_style), 
             tags$h4("some text3", style = bottom_text_style)
          ),
         icon = "fa-eur", color = "warning"
    )
    
    vb4 <- valueBox(
        value = tags$p(paste(100, "%"), style = "font-size: 140%;"),
         caption = div(
             tags$p("My Value Box 4", style = top_text_style), 
             tags$h4("some text4", style = bottom_text_style)
          ),
        icon = "fa-clock", color = "success"
    )
    
    ```
    
    
    My Dashboard {data-icon="fa-search"}
    =======================================================================
    
    ## Row {.sidebar data-width=280 data-padding=10}
    
    ```{r}
    
    tags$h4('My Side Bar')
    tags$hr()
    
    ```
    
    
    Row 
    -----------------------------------------------------------------------
    
    ### {.value-box}
    
    ```{r}
    
    renderValueBox(vb1)
    
    ```
    
    
    ###  {.value-box}
    
    ```{r}
    
    renderValueBox(vb2)
    
    ```
    
    
    ###  {.value-box}
    
    ```{r}
    
    renderValueBox(vb3)
    
    ```
    
    ###  {.value-box}
    
    ```{r}
    
    renderValueBox(vb4)
    
    ```
    
    

    【讨论】:

      猜你喜欢
      • 2019-03-24
      • 2019-09-04
      • 2019-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-22
      • 2015-07-16
      • 2020-09-01
      相关资源
      最近更新 更多