From 1ccbd0cb1e605cc4ed33e9a1e58b8e63efc76f18 Mon Sep 17 00:00:00 2001 From: Elena Arsevska <elena.arsevska@cirad.fr> Date: Mon, 18 Mar 2024 15:43:24 +0100 Subject: [PATCH] Added buttons previous/next but do not do anything. Code taken from: https://stackoverflow.com/questions/44309328/generic-button-for-go-to-next-and-previous-tabitem-shiny --- inst/interface/global.R | 4 +++- inst/interface/server.R | 27 +++++++++++++++++++++++++++ inst/interface/ui.R | 37 +++++++++++++++++++++++++++++-------- 3 files changed, 59 insertions(+), 9 deletions(-) diff --git a/inst/interface/global.R b/inst/interface/global.R index 9ebd069..94e76f6 100644 --- a/inst/interface/global.R +++ b/inst/interface/global.R @@ -9,6 +9,7 @@ library(shinydashboard) library(rhandsontable) library(shinyFiles) library(shinycssloaders) +library(shinyjs) #### MAIN VARIABLES #### @@ -118,4 +119,5 @@ langHelpMatrix <- c( ) - +# Tab item names +tabItemNames = c("fileTab", "unitTab", "riskTab", "weightTab", "resultTab") diff --git a/inst/interface/server.R b/inst/interface/server.R index 8f44e7d..13e9c6e 100644 --- a/inst/interface/server.R +++ b/inst/interface/server.R @@ -251,6 +251,33 @@ server <- function(input, output, session) { }) + + ##### Observer previous/next buttons #### + + observe({ + runjs(" + function getAllElementsWithAttribute(attribute){ + var matchingElements = []; + var allElements = document.getElementsByTagName('*'); + for (var i = 0, n = allElements.length; i < n; i++){ + if (allElements[i].getAttribute(attribute) !== null){ + matchingElements.push(allElements[i]); + } + } + return matchingElements; + }; + + ahref = getAllElementsWithAttribute('data-toggle'); + var tabNames = []; + var tabName = ''; + for (var nr = 0, n = ahref.length; nr < n; nr++){ + tabName = ahref[nr].hash.split('-')[2] + if(tabName != 'Toggle navigation') tabNames.push(tabName) + } + Shiny.onInputChange('tabNames', tabNames); + ") + }) + ##### Observer on layerInfoDF for weight matrix #### observeEvent(rv$layerInfoDF,{ diff --git a/inst/interface/ui.R b/inst/interface/ui.R index 5cc47dd..17d1c4d 100644 --- a/inst/interface/ui.R +++ b/inst/interface/ui.R @@ -9,6 +9,9 @@ sidebar <- dashboardSidebar( + useShinyjs(), # Set up shinyjs + + # Radio buttons to select language radioButtons(inputId = "rbLanguage", label = NULL, @@ -82,7 +85,11 @@ body <- dashboardBody( ) - ) + ), + + #Previous/next button + actionButton(inputId ="Previous", label = icon("arrow-left")), + actionButton(inputId ="Next", label = icon("arrow-right")) ), @@ -106,7 +113,11 @@ body <- dashboardBody( plotOutput("unitStatDisplay") - ) + ), + + #Previous/next button + actionButton(inputId ="Previous", label = icon("arrow-left")), + actionButton(inputId ="Next", label = icon("arrow-right")) ), @@ -137,7 +148,11 @@ body <- dashboardBody( ), - actionButton(inputId = "abInvert", label = langDF["ABRiskRasterInvert", indLang]) + actionButton(inputId = "abInvert", label = langDF["ABRiskRasterInvert", indLang]), + + #Previous/next button + actionButton(inputId ="Previous", label = icon("arrow-left")), + actionButton(inputId ="Next", label = icon("arrow-right")) ), @@ -166,9 +181,11 @@ body <- dashboardBody( ) - ) - + ), + #Previous/next button + actionButton(inputId ="Previous", label = icon("arrow-left")), + actionButton(inputId ="Next", label = icon("arrow-right")) ), @@ -202,11 +219,15 @@ body <- dashboardBody( downloadButton(outputId = "exportResultCSV", label = "Export table") - ) + ), + #Previous/next button + actionButton(inputId ="Previous", label = icon("arrow-left")), + actionButton(inputId ="Next", label = icon("arrow-right")) - ) - + + + ) ) -- GitLab