简体   繁体   English

R-Flexdashboards 中的循环值框

[英]Loop valueboxes in R-Flexdashboards

Happy Easter!复活节快乐!

I wonder if there is any smart programming for looping value boxes (or even better: whole r-markdown -code) in R-flexdashboard s using R-shiny .我想知道在使用R-shiny -shiny 的R-flexdashboard中是否有任何用于循环值框(甚至更好:整个r-markdown -代码)的智能编程。

My problem is:我的问题是:

I have data, which is updated every day.我有数据,每天更新。 Every day I can display several keyfigueres.每天我都可以显示几个 keyfigueres。 I do this with value-boxes , becaus it is very easy to add special colors for different treshholds.我用value-boxes这样做,因为很容易为不同的阈值添加特殊的 colors。

I want to show the data of the last week (7-days), see image, widch show the data for 4 days:我想显示上周(7 天)的数据,见图,显示 4 天的数据:

我的数据展示示例

Is there a possibility to loop my code day by day?有没有可能每天循环我的代码?

My executable code example is only for two days an the valuebox for date (1st column in the image):我的可执行代码示例仅适用于两天的日期值框(图像中的第一列):

---
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")
})

```  

Thank you for any idea to solve my problem.感谢您提供解决我问题的任何想法。

PS: This was not useful, because it is not possible to control the colors for different treshholds PS: 没有用,因为无法针对不同的阈值控制 colors

you have found an Easter egg:你找到了一个复活节彩蛋:

---
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))
        )
    })
})
``` 

  • Impossible to create what you want with original {flexdashboard} package, no way to control row/column layout automatically.无法使用原始 {flexdashboard} package 创建您想要的内容,无法自动控制行/列布局。 However, we can create our own value box.但是,我们可以创建自己的值框。
  • Works the best on bigger screens (> 1000px width), also works on mobile (<670px), different styles will apply on small screens.在大屏幕(> 1000px 宽度)上效果最好,也适用于移动设备(<670px),不同的 styles 将适用于小屏幕。 Medium screens (670-1000) may have some problems, try to change width: 18%;中屏(670-1000)可能会有一些问题,尝试更改width: 18%; to a number you want.到你想要的号码。
  • overflow text due to screen size issues are trimmed off.由于屏幕尺寸问题导致的溢出文本被裁掉。 Change the fontsize argument may also help.更改fontsize参数也可能有帮助。

Bigger screen更大的屏幕

在此处输入图像描述

Mobile移动的

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM