本文介绍了如何使用 Rshiny 和 Rmarkdown 使用两个输入的值框?电阻的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的目标是使用我拥有的一些输入来更新一个值框.
这是我的代码
---标题:《无题》输出:flexdashboard::flex_dashboard:方向:列垂直布局:填充图形:是运行时间:闪亮---```{r 设置,包括 = FALSE}图书馆(弹性仪表板)图书馆(ggplot2)图书馆(情节)图书馆(DT)图书馆(htmltools)图书馆(读者)图书馆(闪亮)图书馆(knitr)``输入 {.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
我的目标是获得一个值框,我可以在其中根据过滤后的剩余数据获得 hp 的总和.
例如,在此屏幕截图中,我进行过滤以仅看到 6 缸和 3 档的汽车.我的目标是在值框中查看 hp 的总和.
附加代码
渲染值框({值框(mtcars2() %>% summarise(Sum=sum(hp)) %>% pull(Sum),paste(总生命值:", input$input2))}) 解决方案
添加
库(dplyr)
到您的 YAML 标头,然后替换
valueBox(0)
与
renderValueBox({值框(总生命值",mtcars2() %>% summarise(Sum=sum(hp)) %>% pull(Sum))})
或类似的.
My goal is to get a value box to update using some inputs I have.
Here is my code
---
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)
```
My goal is to get a value box where I can get the sum of hp depending on the remaining data that is filtered.
For example in this screenshot I filtered to only see cars that are 6 cyl and have 3 gears.My goal would be to see the sum of hp populate on the value box.
Additional Code
renderValueBox({
valueBox(
mtcars2() %>% summarise(Sum=sum(hp)) %>% pull(Sum) ,
paste("Total HP:", input$input2)
)
})
解决方案
Add
library(dplyr)
to your YAML header and then replace
valueBox(0)
with
renderValueBox({
valueBox(
"Total HP",
mtcars2() %>% summarise(Sum=sum(hp)) %>% pull(Sum)
)
})
or similar.
这篇关于如何使用 Rshiny 和 Rmarkdown 使用两个输入的值框?电阻的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!