R-Flexdashboards 中的循环值框

Loop valueboxes in R-Flexdashboards

复活节快乐!

我想知道是否有使用 R-shiny.

R-flexdashboard 中循环值框(或更好:整个 r-markdown 代码)的智能编程

我的问题是:

我有数据,每天更新。 每天我都可以显示几个 keyfigueres。 我用 value-boxes 这样做,因为很容易为不同的 treshholds 添加特殊颜色。

我想显示上周(7天)的数据,看图,显示4天的数据:

是否可以每天循环我的代码?

我的可执行代码示例仅适用于两天和日期值框(图像中的第一列):

---
title: "Test for Loop value boxes"
author: StatistiVolker
output: 
  flexdashboard::flex_dashboard:
    
    orientation: rows
    vertical_layout: fill
runtime: shiny
---

```{r setup, include=FALSE}
require(shiny)
require(flexdashboard)
require(tidyverse)
```

<!-- C19J_Summary.Rmd -->

Testcode
=======================================================================

Sidebar {.sidebar}
-----------------------------------------------------------------------
  
### Settings

```{r}
sliderInput("sliderSumDate",
            "Datum",
            min = as.Date("2020-03-01"),  #min(C19JKInz()$datI),
            max = Sys.Date()-1,
            value = Sys.Date()-1,
            animate = TRUE)

```

```{r}   
# Date
selSumDate <- reactive({
  input$sliderSumDate
})

```

<!-- Is it possible to loop this Code? -->


Row 
-----------------------------------------------------------------------
<!-- actual day -->

###  {.value-box}

```{r}   
# Emit the download count
renderValueBox({
  valueBox(format(as.Date(selSumDate()-0),"%d.%m.%Y (%a)"), 
           caption = "Datum",
           # icon = "fa-calendar", 
           color = "cornflowerblue")
})

``` 

<!-- Next Code is almost the same as above, except one day earlier -->
<!-- Is it possible to loop this Code? -->

Row 
-----------------------------------------------------------------------
<!-- day before -->

###  {.value-box}

```{r}   
# Emit the download count
renderValueBox({
  valueBox(format(as.Date(selSumDate()-1),"%d.%m.%Y (%a)"), 
           caption = "Datum",
           # icon = "fa-calendar", 
           color = "cornflowerblue")
})

```  

感谢您提供解决我问题的任何想法。

PS: 没有用,因为无法控制不同阈值的颜色

您找到了彩蛋:

---
title: "Test for Loop value boxes"
author: StatistiVolker
output: 
  flexdashboard::flex_dashboard:
    
    orientation: rows
    vertical_layout: fill
runtime: shiny
---

```{r setup, include=FALSE}
require(shiny)
require(flexdashboard)
require(tidyverse)
```

<!-- C19J_Summary.Rmd -->
# Sidebar {.sidebar data-width=350}
  
### Settings

```{r}
sliderInput("sliderSumDate",
            "Datum",
            min = as.Date("2020-03-01"),  #min(C19JKInz()$datI),
            max = Sys.Date()-1,
            value = Sys.Date()-1,
            animate = TRUE)

```

```{r}   
# Date
selSumDate <- reactive({
  input$sliderSumDate
})

```

<!-- Is it possible to loop this Code? -->
```{r}
myValueBox <- function(title, caption="", color="cornflowerblue", myicon="", fontsize="25px"){
    div(
        class = "value-box level3",
        style = glue::glue(
            '
            background-color: @{color}@;
            height: 106px;
            width: 18%;
            display: inline-block;
            overflow: hidden;
            word-break: keep-all;
            text-overflow: ellipsis;
            ', .open = '@{', .close = '}@'
        ),
        div(
            class = "inner",
            p(class = "value", title, style = glue::glue("font-size:{fontsize}")),
            p(class = "caption", caption)
        ),
        div(class = "icon", myicon)
    )
}
```


Testcode
=======================================================================
<!-- actual day -->
```{r}
uiOutput("el")
```




```{r}   
# Emit the download count
colors = c("#8b0000", "#000000", "#228b22", "#ffd700")
output$el <- renderUI({
    lapply(0:-6, function(x) {
        div(
            myValueBox(format(as.Date(selSumDate()-x),"%d.%m.%Y (%a)"), "Datum", myicon = icon("calendar")),
            myValueBox(sample(1000, 1), "Infizierte", color = sample(colors, 1)),
            myValueBox(sample(1000, 1), "Aktiv erkrankt", color = sample(colors, 1)),
            myValueBox(sample(1000, 1), "Genesene", color = sample(colors, 1)),
            myValueBox(sample(1000, 1), "Verstorbene", color = sample(colors, 1))
        )
    })
})
``` 

  • 无法使用原始 {flexdashboard} 包创建您想要的内容,无法自动控制 row/column 布局。但是,我们可以创建自己的值框。
  • 在大屏幕(> 1000 像素宽度)上效果最好,也适用于移动设备(<670 像素),不同的样式将适用于小屏幕。中屏(670-1000)可能会出现一些问题,请尝试将width: 18%;更改为您想要的数字。
  • 由于屏幕尺寸问题导致的溢出文本已被裁掉。改变 fontsize 争论也可能有帮助。

更大的屏幕

手机