This repository has been archived by the owner on Mar 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |