在 R flexdashboard 中使用操作按钮
Using action button with R flexdhasboard
是否可以在 R flexdashboard 中使用操作按钮?
例如在下面的 repex 中,是否可以添加一个按钮,以便仅当显示该按钮时代码才会 运行?
我在网站上找不到文档https://garrettgman.github.io/rmarkdown/flexdashboard/using.html#html_widgets
大多数 google 的信息都涉及在“纯”闪亮应用程序而非 flexdashboard 中使用操作按钮。
---
title: "example"
runtime: shiny
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
---
```{r setup, include=FALSE}
library(flexdashboard)
```
Column {data-width=100}
-----------------------------------------------------------------------
### Chart A
```{r}
numericInput("n1", "First number", 10)
```
Column {data-width=900}
-----------------------------------------------------------------------
### Chart B
```{r}
DT::renderDataTable({
x = sample(1:input$n1, size=500, replace=TRUE)
x= as.data.frame(x)
DT::datatable(x, options = list(
bPaginate = FALSE
))
})
```
是的,这是可能的。您可以像使用 numericInput
一样包含 actionButton
然后例如使用 eventReactive
编程模式:
---
title: "example"
runtime: shiny
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
---
```{r setup, include=FALSE}
library(flexdashboard)
```
Column {data-width=100}
-----------------------------------------------------------------------
### Chart A
```{r}
numericInput("n1", "First number", 10)
actionButton("execute", "Generate data")
```
Column {data-width=900}
-----------------------------------------------------------------------
### Chart B
```{r}
table_data <- eventReactive(input$execute, {
x = sample(1:input$n1, size=500, replace=TRUE)
as.data.frame(x)
})
DT::renderDataTable({
req(table_data())
DT::datatable(table_data(), options = list(
bPaginate = FALSE
))
})
```
是否可以在 R flexdashboard 中使用操作按钮?
例如在下面的 repex 中,是否可以添加一个按钮,以便仅当显示该按钮时代码才会 运行?
我在网站上找不到文档https://garrettgman.github.io/rmarkdown/flexdashboard/using.html#html_widgets
大多数 google 的信息都涉及在“纯”闪亮应用程序而非 flexdashboard 中使用操作按钮。
---
title: "example"
runtime: shiny
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
---
```{r setup, include=FALSE}
library(flexdashboard)
```
Column {data-width=100}
-----------------------------------------------------------------------
### Chart A
```{r}
numericInput("n1", "First number", 10)
```
Column {data-width=900}
-----------------------------------------------------------------------
### Chart B
```{r}
DT::renderDataTable({
x = sample(1:input$n1, size=500, replace=TRUE)
x= as.data.frame(x)
DT::datatable(x, options = list(
bPaginate = FALSE
))
})
```
是的,这是可能的。您可以像使用 numericInput
一样包含 actionButton
然后例如使用 eventReactive
编程模式:
---
title: "example"
runtime: shiny
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
---
```{r setup, include=FALSE}
library(flexdashboard)
```
Column {data-width=100}
-----------------------------------------------------------------------
### Chart A
```{r}
numericInput("n1", "First number", 10)
actionButton("execute", "Generate data")
```
Column {data-width=900}
-----------------------------------------------------------------------
### Chart B
```{r}
table_data <- eventReactive(input$execute, {
x = sample(1:input$n1, size=500, replace=TRUE)
as.data.frame(x)
})
DT::renderDataTable({
req(table_data())
DT::datatable(table_data(), options = list(
bPaginate = FALSE
))
})
```