2

I'm trying to create a flexdashboard in R Markdown which runs a certain code chunk when clicking on an actionbutton. I.e. at the start of the dashboard, a questionnaire with radiobuttons appears, whereas when clicking on the button "Submit Answers", the questionnaire should disappear and a text should come up. At the moment, nothing happens when I click on the Submit-Button. What am I doing wrong?

Here is what I've tried so far:

---
title: "Questionnaire"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: scroll
    css: www/styles.css
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(readxl)
library(openxlsx)
library(janitor)
library(data.table)
library(plotly)
library(shiny)
library(ggplot2)
library(rmarkdown)
library(CssDwhSpark)
library(tidyverse)
library(tibble)
library(shinydashboard)
library(DT)
library(shinyWidgets)
library(editData)
library(knitr)
```
```{r}
eval1 = reactiveVal(TRUE)
eval2 = reactiveVal(FALSE)

observeEvent(input$submit, {
  isolate(eval1(FALSE))
  isolate(eval2(TRUE))
  })
```
```{r, chunk1, eval = eval1()}
asis_output("## Row\n### Satisfaction\nHow satisfied are you with the     service?\n")

fluidPage(
radioButtons(
inputId = "answer1",
label = NULL,
choices = c("Very satisfied", "Satisfied", "Not satisfied"),
selected = character(0),
width = '100%'
))

asis_output("## Row\n### Recommandation\nHow probable is it that you would recommend our service?\n")

fluidPage(
radioButtons(
inputId = "answer2",
label = NULL,
choices = c("Very probable", "Probable", "Not probable"),
selected = character(0),
width = '100%'
))

asis_output("## Row\n")
fluidPage(
  actionButton(inputId = "submit", label = "Submit Answers")
)

```
```{r, chunk2, eval = eval2()}
asis_output("## Row\n")
h4("Thank you for filling up our questionnaire!")
```
halfer
  • 19,824
  • 17
  • 99
  • 186

0 Answers0