Skip to content
This repository has been archived by the owner on Mar 11, 2020. It is now read-only.

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
earnaud authored May 7, 2019
1 parent 2112920 commit 59100e5
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 0 deletions.
84 changes: 84 additions & 0 deletions templateApp/templateApp.R
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)
41 changes: 41 additions & 0 deletions templateApp/templateModule.R
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)

0 comments on commit 59100e5

Please sign in to comment.