From c65409a2698133e862b2d9c1555a53e42ca2dc95 Mon Sep 17 00:00:00 2001
From: parisa-zahedi
Date: Tue, 16 Jul 2024 10:37:34 +0200
Subject: [PATCH] disable tabs if akkoord is unchecked
---
mod-disclaimer.R | 27 ++++++-
survey-app.R | 183 ++++++++++++++++++++++++-----------------------
2 files changed, 120 insertions(+), 90 deletions(-)
diff --git a/mod-disclaimer.R b/mod-disclaimer.R
index 875262b..1cb6120 100644
--- a/mod-disclaimer.R
+++ b/mod-disclaimer.R
@@ -1,3 +1,20 @@
+# This file is part of Empathy-viz.
+
+# Copyright (C) 2024 Minet de Wied & SodaScience
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+
source("questions.R")
library(shiny)
@@ -42,7 +59,7 @@ disclaimerUI <- function(id) {
),
fluidRow(
column(12,
- checkboxInput(ns("akkoord"), "Ik ga akkoord met de algemene voorwaarden.")
+ checkboxInput(ns("akkoord"), "Akkoord")
)
),
fluidRow(
@@ -94,6 +111,7 @@ disclaimerServer <- function(id, parent.session, tabset.id, tab.target, disclaim
observeEvent(input$ok, {
if (input$akkoord) {
updateTabsetPanel(parent.session, tabset.id, selected = tab.target)
+ shinyjs::enable(selector = "#main\\.navbar li a")
} else {
showModal(modalDialog(
title = "Toestemming Vereist",
@@ -101,6 +119,13 @@ disclaimerServer <- function(id, parent.session, tabset.id, tab.target, disclaim
easyClose = TRUE,
footer = NULL
))
+ shinyjs::disable(selector = "#main\\.navbar li a")
+ }
+ })
+
+ observe({
+ if (!input$akkoord) {
+ shinyjs::disable(selector = "#main\\.navbar li a")
}
})
})
diff --git a/survey-app.R b/survey-app.R
index 2462a51..62a8ffa 100644
--- a/survey-app.R
+++ b/survey-app.R
@@ -16,6 +16,7 @@
# along with this program. If not, see .
library(shiny)
+library(shinyjs)
source("mod-disclaimer.R")
source("mod-question.R")
source("mod-image.R")
@@ -26,101 +27,95 @@ source("mod-visRelationship.R")
source("mod-visEmotions.R")
source("mod-visRelEmo.R")
-ui <- navbarPage(theme = bslib::bs_theme(bootswatch = "flatly"),
- id = "main.navbar",
- # Application title
- "Empathie in Beeld",
- shinyjs::useShinyjs(),
-
- # Start Disclaimer-tab
- tabPanel(
- "Disclaimer",
-
- # Disclaimer-tab body
- wellPanel(
- #style= "min-width: 300px;max-width: 400px;overflow:auto",
- #verticalLayout(
- disclaimerUI("dsc1")
- #)
- )
- ),
- # End Disclaimer-tab
-
- # Start Input-tab
- tabPanel(
- title = "Input",
- value = "input_tab",
-
- # Input-tab body
- wellPanel(
- style= "min-width: 300px;max-width: 400px;overflow:auto",
- verticalLayout(
- inputUI("inp1")
- )
- )
- ),
- # End Input-tab
-
-
- # Start Questionnaire-tab
- tabPanel(
- title = "Vragenlijst",
- value = "tvrag",
-
- # Progress bar
- sidebarLayout(
- sidebarPanel(
- imageUI("img1"),
- width = 3
-
- ),
-
- mainPanel(
- questionUI("surv1") ,
- width = 9
- )
- )
- ),
- # End Questionnaire-tab
-
- # Start Visualization-tab
- tabPanel(
- "Visualisatie",
- tabsetPanel(
- id = "vistab",
- tabPanel(title = "Selecteer Dataset",
- value = "tdataset",
- visDatasetUI("visDataset1")
- ),
- navbarMenu("Dynamiek in relaties",
- tabPanel(title = "Blijdschap",
- value = "tblij",
- visRelationshipUI("visRelationship2")),
- tabPanel(title = "Verdriet",
- value = "tverd",
- visRelationshipUI("visRelationship3")),
- tabPanel(title = "Pijn",
- value = "tpijn",
- visRelationshipUI("visRelationship1"))
-
- ),
- tabPanel("Relaties * Emoties",
- visRelEmoUI("visRelEmo1")),
- tabPanel(title = "Dynamiek in emoties",
- value = "temo",
- visEmotionUI("visEmotion1")
- )
- ))
- # End Visualization-tab
-
+ui <- navbarPage(
+ theme = bslib::bs_theme(bootswatch = "flatly"),
+ id = "main.navbar",
+ title = "Empathie in Beeld",
+ shinyjs::useShinyjs(),
+
+ # Disclaimer-tab
+ tabPanel(
+ "Disclaimer",
+ wellPanel(
+ disclaimerUI("dsc1")
+ )
+ ),
+
+ # Input-tab
+ tabPanel(
+ title = "Input",
+ value = "input_tab",
+ wellPanel(
+ style = "min-width: 300px;max-width: 400px;overflow:auto",
+ verticalLayout(
+ inputUI("inp1")
+ )
+ )
+ ),
+
+ # Questionnaire-tab
+ tabPanel(
+ title = "Vragenlijst",
+ value = "tvrag",
+ sidebarLayout(
+ sidebarPanel(
+ imageUI("img1"),
+ width = 3
+ ),
+ mainPanel(
+ questionUI("surv1"),
+ width = 9
+ )
+ )
+ ),
+
+ # Visualization-tab
+ tabPanel(
+ "Visualisatie",
+ tabsetPanel(
+ id = "vistab",
+ tabPanel(
+ title = "Selecteer Dataset",
+ value = "tdataset",
+ visDatasetUI("visDataset1")
+ ),
+ navbarMenu(
+ "Dynamiek in relaties",
+ tabPanel(
+ title = "Blijdschap",
+ value = "tblij",
+ visRelationshipUI("visRelationship2")
+ ),
+ tabPanel(
+ title = "Verdriet",
+ value = "tverd",
+ visRelationshipUI("visRelationship3")
+ ),
+ tabPanel(
+ title = "Pijn",
+ value = "tpijn",
+ visRelationshipUI("visRelationship1")
+ )
+ ),
+ tabPanel(
+ "Relaties * Emoties",
+ visRelEmoUI("visRelEmo1")
+ ),
+ tabPanel(
+ title = "Dynamiek in emoties",
+ value = "temo",
+ visEmotionUI("visEmotion1")
+ )
+ )
+ )
)
+
server <- function(input, output, session) {
counter <- reactiveVal(0)
input.data <- reactiveValues(gender = NULL, age = NULL, code = NULL)
df.survey <- reactiveValues(data = NULL)
df.vis <- reactiveValues(data = NULL)
disclaimer_file_path = "data/disclaimer.csv"
-
questionServer("surv1", "data/introduction.csv","data/vignettes.csv",
"data/relationships.csv", "data/RadioMatrixFrame.csv",
"data/ending.csv",counter,input.data,df.survey)
@@ -133,5 +128,15 @@ server <- function(input, output, session) {
visRelationshipServer("visRelationship3",df.vis,"data/vignettes.csv","data/guideline_vis.csv",'verdriet')
visEmotionServer("visEmotion1","data/guideline_vis.csv",df.vis)
visRelEmoServer("visRelEmo1","data/guideline_vis.csv",df.vis)
+
+ # Disable all tabs except Disclaimer initially
+ shinyjs::disable(selector = "#main\\.navbar li a[data-value='input_tab']")
+ shinyjs::disable(selector = "#main\\.navbar li a[data-value='tvrag']")
+ shinyjs::disable(selector = "#main\\.navbar li a[data-value='tdataset']")
+ shinyjs::disable(selector = "#main\\.navbar li a[data-value='tblij']")
+ shinyjs::disable(selector = "#main\\.navbar li a[data-value='tverd']")
+ shinyjs::disable(selector = "#main\\.navbar li a[data-value='tpijn']")
+ shinyjs::disable(selector = "#main\\.navbar li a[data-value='temo']")
}
-shinyApp(ui, server)
+
+shinyApp(ui, server)
\ No newline at end of file