I have designed an R markdown doc that has combination of r code chunks, inline r, and various render functions.
I've put a couple of Shiny inputs in the doc, and I want to feed those inputs into two variables early in the r code, and then the various code segments later in the doc can depend on those variables. Some examples of the code are below.
I am having problems getting this doc to work. ("Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)")
Would be great if I could get some advice on how to edit the code to work.
# set up shiny input
``` {r echo = FALSE}
inputPanel(
textInput("fmno","Enter code", placeholder = "Code"),
selectInput("comparator", "Choose your comparator", choices = c("OP", "GE"), selected = "GE")
)
```
# feed inputs into variables in r code for use later in doc
```{r}
fmno <- reactive({get(input$fmno)})
comparator <- reactive({get(input$comparator)})
person_table <- person_table[person_table$fmno == fmno, ]
op_table <- op_table[op_table$op == op, ]
ge_table <- ge_table[ge_table$ge == ge, ]
if (comparator == "OP") {
comp_table <- op_table
comp <- op
} else {
comp_table <- ge_table
comp <- ge
}
```