我的目标是使用我拥有的一些输入来更新值框。
这是我的代码
---
title: "Untitled"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
graphics: yes
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(ggplot2)
library(plotly)
library(DT)
library(htmltools)
library(readr)
library(shiny)
library(knitr)
```
Inputs {.sidebar data-width=300}
=====================================
```{r}
selectInput("input_type","Select Cylinder Size: ", c("All", mtcars$cyl))
selectInput("input_type2", "Select # of Gears: ", c("All", mtcars$gear))
mtcars2 <- reactive({
d <- mtcars
if(input$input_type !="All")
d <- subset(d, cyl == input$input_type)
if(input$input_type2 !="All")
d <- subset(d, gear == input$input_type2)
d
})
```
# Page 1
Column {data-width=600}
-----------------------------------------------------------------------
### Table
```{r echo=FALSE}
renderDataTable(
datatable(mtcars2())
)
```
Column {data-width=300}
-----------------------------------------------------------------------
### Value Box
```{r}
valueBox(0)
```
我的目标是获得一个值框,我可以在其中获得 hp 的总和,具体取决于过滤的剩余数据。
例如,在这个屏幕截图中,我过滤后只看到 6 缸和 3 个齿轮的汽车。我的目标是查看值框上填充的 hp 总和。
附加代码
renderValueBox({
valueBox(
mtcars2() %>% summarise(Sum=sum(hp)) %>% pull(Sum) ,
paste("Total HP:", input$input2)
)
})