0

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")
})

```
SteveM
  • 2,226
  • 3
  • 12
  • 16
  • 1
    without a reproducible example one can only guess.`df[, 1]` seems to be of type double and `input$data1` not? Have you tried something like: `if(!is.null(input$data1)) df[1, 1] <- reactive({as.numeric(input$data1)})`? – Tonio Liebrand Aug 09 '18 at 17:19
  • Thanks for the reply. Your line of code produces the error msg: "Operation not allowed without an active reactive context" – SteveM Aug 09 '18 at 18:33
  • then try to remove the if statement. Alternatively you will have to share reproducible code,... – Tonio Liebrand Aug 09 '18 at 20:30
  • Thanks for your additional reply. I edited the original post, adding the entire .Rmd file code. Apologize for any site protocol errors. Appreciate the assistance. – SteveM Aug 09 '18 at 21:34
  • Not sure what you want to achieve but you can try: `observeEvent(input$data1, df[1, 1] <<- input$data1 # does not work )` – Tonio Liebrand Aug 10 '18 at 13:43
  • Thanks. It works partially. I.e. it does show the initial value (50) of the linked slider widget in the renderValueBox. But the ValueBox is decoupled from further changes in the slider. My purpose is this. I'm running an optimization model and want to export the constraint parameters along with the solution so the user has a reference. My idea is to have the parameters set using shiny widgets, save those widget values to a dataframe and then export the dataframe. – SteveM Aug 10 '18 at 15:29
  • Again it is not that clear what you want to achieve. I made one last attempt in the answer. Otherwise i wish you good luck and a nice week-end :) – Tonio Liebrand Aug 10 '18 at 15:47

1 Answers1

1

Maybe you are looking for this:

```{r}
global <- reactiveValues(df = df)
observeEvent(input$data1, global$df[1, 1] <- input$data1)
renderPrint(global$df)
```
Tonio Liebrand
  • 17,189
  • 4
  • 39
  • 59