diff --git a/templateApp/templateApp.R b/templateApp/templateApp.R new file mode 100644 index 0000000..943aad1 --- /dev/null +++ b/templateApp/templateApp.R @@ -0,0 +1,84 @@ +### This script is for development purposes only. It shall not +### be called in other part of the EML UI ShinyApp (current +### directory). + +### Lexica +# * fieldName: user-friendly name for the filled information +# (e.g. 'fieldName' for the xml tag name) +# * xmlElement: technical name for the filled information +# (= xml tag name) +# * + +library(shiny) + +### functions ### + +# display a row and shows its memorized value on the right +simpleInputRow <- function(fieldName, + xmlTag, + placeholder = NULL){ + splitLayout( + textInput(inputId = xmlTag, + paste(fieldName," (",xmlTag,")"), + placeholder = placeholder), + h4(textOutput(xmlTag)) + ) + +} + +####### UI ####### + +xmlElements = c("gentleAndComprehensibleWord_1", + "gentleAndComprehensibleWord_2") +xmlAttributes = c("technicalId_1", + "technicalId_2") +placeholders = paste("e.g.", + c("example_1", + "example_2")) + +if(length(xmlElements) != length(xmlAttributes) + || length(placeholders) != length(xmlAttributes) + || length(xmlElements) != length(placeholders)) + stop("[Dev] xmlElements, xmlAttributes and placeholders length differ !") + +ui <- fluidPage( + splitLayout( + h2("Enter information"), + h2("Gathered information") + ), + + lapply(1:length(xmlElements), + function(i){ + simpleInputRow(xmlElements[i], + xmlAttributes[i], + placeholders[i]) + } + ), + actionButton(style="position:absolute;left:1em;bottom:1em;", + "main_menu", "Main menu"), + actionButton(style = "position:absolute;right:1em;bottom:1em;", + "proceed", "Proceed") + + + +) + +##### Server ##### + +server <- function(input, + output){ + + # verbose function + lapply(1:length(xmlElements), + function(i){ + attribute <- xmlAttributes[i] + output[[attribute]] <- reactive({ + input[[attribute]] + }) + }) + +} + +#### LaunchApp #### + +shinyApp(ui, server) \ No newline at end of file diff --git a/templateApp/templateModule.R b/templateApp/templateModule.R new file mode 100644 index 0000000..45e95d8 --- /dev/null +++ b/templateApp/templateModule.R @@ -0,0 +1,41 @@ +### templateShinyModule.R + +# this document is not to be run + +# snake_case terms are to be replaced with the wanted terms + +ui_function <- function(id, arguments_){ + # necessary namespace + ns = NS(id) + + # UI elements and their $arguments_ + # ui_element(ns(args), arguments_) + + # namespaced arguments will be able to react to server functions + # who are called (cf. callModule) with the correct id +} + +server_function <- function(input, output,session, arguments_){ + # anaything a server function would do without mentioning output + # var + + # server_function is to be called in the main script using the + # callModule() function with these arguments + # - name of the server_function + # - corresponding ui_element id + # - arguments of the server_function + # the output var is built in the main script +} + +### main.R +library(shiny) + +ui <- ui_layout( + ui_function("id_") +) + +server <- function(input, output, session){ + output <- callModule(server_function, "id_", arguments_) +} + +shinyApp(ui,server) \ No newline at end of file