Search code examples
rshinyflexdashboard

Assign Flexdashboard reactive input value to dataframe cell


I want to copy some flexdashboard reactive input values to a dataframe so that I can export them to a file. This code works for y as a scalar:

y <- reactive({input$data1})

But this code does not with df a dataframe with an empty column declared as numeric:

df[1, 1] <- reactive({input$data1})

Error: Incompatible types (from closure to double) in subassignment type fix

Can someone help me with the proper syntax to do the assignment? Thanks...

Not sure on how to submit reproducible code. Here is the entire .Rmd for this issue:

---
title: "Untitled"
runtime: shiny
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
---

```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)

df <- data.frame(MinVals = numeric(), MaxVals = numeric())

```

Inputs {.sidebar data-width=275}
-----------------------------------------------------------------------

```{r}

tags$h3("Test It")

sliderInput("data1",
             label = "Some data",
             value = 50,
             min = 0,
             max = 100,
             step = 5,
             width = 200)


```

Column {data-width=350}
-----------------------------------------------------------------------

### Chart A

```{r}

df[1, 1] <- reactive({input$data1})  # does not work

y <- reactive({input$data1}) # this works

renderValueBox({
    x <- y()
  valueBox(
    value = x,
    icon = "fa-area-chart",
    color = "orange")
})

```

Solution

  • Maybe you are looking for this:

    ```{r}
    global <- reactiveValues(df = df)
    observeEvent(input$data1, global$df[1, 1] <- input$data1)
    renderPrint(global$df)
    ```