【问题标题】:Using action button with R flexdhasboard使用带有 R flexdhasboard 的操作按钮
【发布时间】:2020-11-01 18:19:47
【问题描述】:

是否可以在 R flexdashboard 中使用操作按钮?

例如在下面的 repex 中,是否可以添加一个按钮,以便代码仅在显示按钮时运行?

我在https://garrettgman.github.io/rmarkdown/flexdashboard/using.html#html_widgets网站上找不到文档

谷歌的大部分信息都涉及在“纯”闪亮的应用程序中使用操作按钮,而不是 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
  ))
})


```

【问题讨论】:

    标签: r shiny flexdashboard


    【解决方案1】:

    是的,这是可能的。您可以像使用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
      ))
    })
    
    
    ```
    

    【讨论】:

    • 谢谢,这正是我想要的,它很简单,可以理解并应用于其他场景。
    • 谢谢你,它必须使用 ggplot 而不是数据表?
    • 您可以使用renderPlot 代替renderDataTable 并将ggplot 代码放入其中
    猜你喜欢
    • 2015-11-26
    • 2017-12-18
    • 2015-09-18
    • 1970-01-01
    • 1970-01-01
    • 2013-02-23
    • 1970-01-01
    • 2017-02-16
    • 1970-01-01
    相关资源
    最近更新 更多