Skip to content

Commit

Permalink
shiny app : add API import
Browse files Browse the repository at this point in the history
  • Loading branch information
Benoit Thieurmel committed Sep 29, 2021
1 parent 501f34d commit c666a78
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 39 deletions.
40 changes: 35 additions & 5 deletions inst/application/src/server/01_set_read_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ rdsData <- reactive({
output$directory_message <- renderText({
if(length(input$directory) > 0){
if(input$directory == 0){
antaresViz:::.getLabelLanguage("Or choose a folder with antares output", current_language$language)
antaresViz:::.getLabelLanguage("Choose a folder with antares output", current_language$language)
} else {
antaresViz:::.getLabelLanguage("No antares output found in directory", current_language$language)
}
Expand Down Expand Up @@ -110,7 +110,9 @@ observe({
})

# init opts after validation
opts <- reactive({
opts <- reactiveVal(NULL)

observe({
if(input$init_sim > 0){
opts <-
tryCatch({
Expand All @@ -120,7 +122,7 @@ opts <- reactive({
title = "Error setting file",
easyClose = TRUE,
footer = NULL,
paste("Directory/file is not an Antares study : ", e, sep = "\n")
paste("Directory/file is not an Antares study : ", e$message, sep = "\n")
))
NULL
})
Expand All @@ -140,9 +142,37 @@ opts <- reactive({
}
}
}
opts
opts(opts)
} else {
NULL
opts(NULL)
}
})

observe({
if(input$init_sim_api > 0){
opts <-
tryCatch({
setSimulationPathAPI(
host = isolate(input$api_host),
study_id = isolate(input$api_study_id),
token = isolate(input$api_token),
simulation = isolate(input$api_simulation)
)
}, error = function(e){
showModal(modalDialog(
title = "Error reading API",
easyClose = TRUE,
footer = NULL,
e$message
))
NULL
})
if(!is.null(opts)){
opts$h5 <- FALSE
}
opts(opts)
} else {
opts(NULL)
}
})

Expand Down
12 changes: 12 additions & 0 deletions inst/application/src/server/08_language.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ observe({
# params
updateCheckboxInput(session, "is_shared_input", antaresViz:::.getLabelLanguage("Share inputs between modules ?", current_language$language))

# import type
cur_type_import <- isolate({input$type_import})
choice <- c("local", "RDS", "API")
sel <- which(choice %in% cur_type_import)
names(choice) <- c(
antaresViz:::.getLabelLanguage("Local Antares Study", current_language$language),
antaresViz:::.getLabelLanguage("R file .RDS", current_language$language),
antaresViz:::.getLabelLanguage("API Antares", current_language$language)
)
updateSelectInput(session, "type_import",
label = ,
choices = choice, selected = choice[sel])
})

output$current_opts <- renderText({
Expand Down
102 changes: 69 additions & 33 deletions inst/application/src/ui/01_ui_import_data.R
Original file line number Diff line number Diff line change
@@ -1,38 +1,74 @@
tabPanel(textOutput("label_tab_import_data"),
h3(textOutput("title_import_data")),
fluidRow(
column(4,
fileInput("fileRDS",
label = NULL,
# antaresViz:::.getLabelLanguage("Choose rds File who contains antares data"),
accept = ".rds", width = "100%")),
column(8,
h3(textOutput("directory_message2"), style = "color : red;margin-top:0px")
column(6, h3(textOutput("title_import_data"))),
column(6,
selectInput("type_import", "",
choices = c("Etude Antares locale" = "local", "Fichier R .RDS" = "RDS", "API Antares" = "API"), width = "100%")
)
),
fluidRow(
column(4,
directoryInput('directory', label = '', value = 'C:\\Users\\Datastorm\\Documents\\git\\bpNumerique2018\\inst\\application_bp\\data')
),
conditionalPanel(condition = "output.ctrl_is_antares_study | output.ctrl_is_antares_h5",
column(1,
div(br(), h4("Simulation : "), align = "center")

conditionalPanel(condition = "input.type_import === 'RDS'",
fluidRow(
column(4,
fileInput("fileRDS",
label = NULL,
# antaresViz:::.getLabelLanguage("Choose rds File who contains antares data"),
accept = ".rds", width = "100%")),
column(8,
h3(textOutput("directory_message2"), style = "color : red;margin-top:0px")
)
)
),

conditionalPanel(condition = "input.type_import === 'local'",
fluidRow(
column(4,
directoryInput('directory', label = '', value = 'C:\\Users\\Datastorm\\Documents\\git\\bpNumerique2018\\inst\\application_bp\\data')
),
conditionalPanel(condition = "output.ctrl_is_antares_study | output.ctrl_is_antares_h5",
column(1,
div(br(), h4("Simulation : "), align = "center")
),
column(4,
selectInput("study_path", "", choices = NULL, selected = NULL, width = "100%")
),
column(2,
div(br(),
actionButton("init_sim", "Set simulation", icon = icon("check-circle")),
align = "center"
)
)
),
conditionalPanel(condition = "output.ctrl_is_antares_study === false & output.ctrl_is_antares_h5 === false",
column(8,
h3(textOutput("directory_message"), style = "color : red")
)
)
)
),

conditionalPanel(condition = "input.type_import === 'API'",
fluidRow(
column(3,
textInput('api_host', label = 'Host :', value = '')
),
column(3,
textInput('api_study_id', label = 'Study id :', value = '')
),
column(4,
selectInput("study_path", "", choices = NULL, selected = NULL, width = "100%")
textInput('api_token', label = 'Token :', value = '', width = "100%")
),
column(1,
numericInput('api_simulation', label = 'simulation :', value = 1, min = 1, step = 1)
),
column(2,
column(1,
div(br(),
actionButton("init_sim", "Set simulation", icon = icon("check-circle")),
actionButton("init_sim_api", "Go!",
icon = icon("check-circle"), style = "margin-top:5px"),
align = "center"
)
)
),
conditionalPanel(condition = "output.ctrl_is_antares_study === false & output.ctrl_is_antares_h5 === false",
column(8,
h3(textOutput("directory_message"), style = "color : red")
)
)
)
),

conditionalPanel(condition = "output.have_study",
Expand Down Expand Up @@ -136,14 +172,14 @@ tabPanel(textOutput("label_tab_import_data"),
)
),

fluidRow(
column(3,
h4(textOutput("title_hvdc"))

),


column(9, selectInput("hvdc", "hvdc", choices = NULL, selected = NULL, multiple = TRUE))),
fluidRow(
column(3,
h4(textOutput("title_hvdc"))
),
column(9, selectInput("hvdc", "hvdc", choices = NULL, selected = NULL, multiple = TRUE))),
div(actionButton("import_data", "Validate & import data", icon = icon("upload")), align = "center"),

# convert h5
Expand Down Expand Up @@ -248,7 +284,7 @@ tabPanel(textOutput("label_tab_import_data"),
),



fluidRow(
column(12,
div(actionButton("write_h5", "Convert study to h5", icon = icon("floppy-o")), align = "center") )
Expand Down
5 changes: 4 additions & 1 deletion inst/language_labels.csv
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ No data imported;Pas de données importées
No areas imported;Pas noeuds importés
No links imported;Pas de liens importés
No antares output found in directory;Pas d'étude(s) antares trouvée(s) dans le répertoire
Or choose a folder with antares output; Ou sélectionner un répertoire contenant des études antares
Choose a folder with antares output; Sélectionner un répertoire contenant des études antares
Please set or import a map layout before;Editer ou importer le positionnement des points
Download Layout;Télécharger le positionnement
Import a layout;Importer un positionnement
Expand All @@ -157,3 +157,6 @@ Choose rds File who contains antares data;Choisir un fichier .RDS avec des donn
Hvdc areas;Zones Hvdc
updateLegendOnMouseOver;Maj légende par survol
closePopupOnClick;Fermer les popups à chaque clic
Local Antares Study;Etude Antares locale
R file .RDS;Fichier R .RDS
API Antares;API Antares

0 comments on commit c666a78

Please sign in to comment.