Téléverser les fichiers vers "/"

This commit is contained in:
aslane 2024-03-04 07:26:25 +00:00
parent 034f4e111e
commit 587f6857b7
3 changed files with 1351 additions and 1232 deletions

View File

@ -1,7 +1,9 @@
FROM rocker/r-ver FROM rocker/r-ver
# Create a new group and user for Shiny
RUN groupadd shiny && useradd -r -m shiny -g shiny RUN groupadd shiny && useradd -r -m shiny -g shiny
# Install system dependencies
RUN apt-get update \ RUN apt-get update \
&& apt-get install -y --no-install-recommends \ && apt-get install -y --no-install-recommends \
pandoc \ pandoc \
@ -14,26 +16,28 @@ RUN apt-get update \
libicu-dev \ libicu-dev \
wget wget
RUN R -e "install.packages(c('dplyr', 'shiny', 'readxl','remotes','httpuv','shinythemes','DT','ggplot2','gridExtra','emmeans','officer'), repos = 'https://cran.rstudio.com/', method='wget')" # Install R packages
RUN R -e 'install.packages("factoextra")' RUN R -e 'install.packages("remotes")'
RUN R -e 'install.packages("officer")' RUN R -e "install.packages(c('dplyr', 'shiny', 'readxl', 'remotes', 'httpuv', 'shinythemes', 'DT', 'ggplot2', 'gridExtra', 'emmeans', 'officer', 'car', 'markdown', 'plotly', 'factoextra', 'shinylogs', 'auth0', 'httr', 'shinyjs'), repos = 'https://cran.rstudio.com/', method='wget')"
RUN R -e 'install.packages("car")' RUN R -e 'install_dev("shiny")'
RUN R -e 'install.packages("markdown")'
RUN R -e 'install.packages("plotly")'
RUN R -e 'install.packages("shinylogs")'
# Create a directory for your Shiny app
RUN mkdir -p /srv/shiny && \ RUN mkdir -p /srv/shiny && \
chown shiny:shiny /srv/shiny chown shiny:shiny /srv/shiny
# Copy the Shiny app to the container
COPY app.R /srv/shiny/app.R COPY app.R /srv/shiny/app.R
COPY README.md /srv/shiny/README.md COPY README.md /srv/shiny/README.md
COPY arbre1.png /srv/shiny/arbre1.png COPY arbre1.png /srv/shiny/arbre1.png
COPY arbre2.png /srv/shiny/arbre2.png COPY arbre2.png /srv/shiny/arbre2.png
COPY .Renviron /srv/shiny/.Renviron
# Expose the port Shiny app runs on
EXPOSE 8080 EXPOSE 8080
# Use the created shiny user
USER shiny USER shiny
# Command to run the Shiny app
CMD ["R", "-e", "shiny::runApp('/srv/shiny', host='0.0.0.0', port=8080, launch.browser = FALSE)"]
CMD ["R", "-e", "shiny::runApp('/srv/shiny', host='0.0.0.0', port=8080, launch.browser = F)"]

7
_auth0.yml Normal file
View File

@ -0,0 +1,7 @@
name: Stat_Plateform
remote_url: ''
auth0_config:
api_url: !expr paste0('https://', Sys.getenv("AUTH0_USER"), '.okta.com/oauth2/default/v1')
credentials:
key: !expr Sys.getenv("AUTH0_KEY")
secret: !expr Sys.getenv("AUTH0_SECRET")

132
app.R
View File

@ -10,15 +10,49 @@ library(car)
library(factoextra) library(factoextra)
library(shinylogs) library(shinylogs)
library(plotly) library(plotly)
library(auth0)
library(httr)
library(shinyjs)
library(openssl)
library(urltools)
client_id <- Sys.getenv("CLIENT_ID")
client_secret <- Sys.getenv("CLIENT_SECRET")
uri_url <- Sys.getenv("URI_URL")
authorize_url = Sys.getenv("AUTHORIZE_URL")
token_url = Sys.getenv("TOKEN_URL")
userinfo_url = Sys.getenv("USERINFO_URL")
response_type <- 'code'
ui <- fluidPage( ui <- fluidPage(
useShinyjs(),
# Ici on empêche l'utilisateur de pouvoir rafraîchir la page accidentellement
tags$script('
window.onbeforeunload = function() {
return "Voulez-vous vraiment quitter cette page ?";
};
'),
# Ici on a créé une fonction permettant de masquer tous les éléments de la page
extendShinyjs(text = "
shinyjs.hideAllElements = function() {
$('body > *').hide();
}
",functions="shinyjs.hideAllElements"),
theme = shinytheme("readable"), theme = shinytheme("readable"),
navbarPage( navbarPage(
"Stat Plateform", "Stat Plateform",
tabPanel("Accueil", tabPanel("Accueil",
fluidRow( fluidRow(
column(4, column(4,
textOutput("welcome"),
wellPanel( wellPanel(
fileInput("files", "Sélectionnez les fichiers Excel (xlsx) :", multiple = TRUE), fileInput("files", "Sélectionnez les fichiers Excel (xlsx) :", multiple = TRUE),
selectInput("ignore_columns", "Colonnes à ignorer :", multiple = TRUE, choices = NULL), selectInput("ignore_columns", "Colonnes à ignorer :", multiple = TRUE, choices = NULL),
@ -68,7 +102,6 @@ ui <- fluidPage(
style = 'overflow-x: scroll;height: 650px;', style = 'overflow-x: scroll;height: 650px;',
DT::dataTableOutput("anova_table"), DT::dataTableOutput("anova_table"),
downloadButton("anova_button_download", "Télécharger le tableau",class="btn-primary") downloadButton("anova_button_download", "Télécharger le tableau",class="btn-primary")
), ),
wellPanel( wellPanel(
style = 'overflow-x: scroll;height: 650px;', style = 'overflow-x: scroll;height: 650px;',
@ -81,7 +114,22 @@ ui <- fluidPage(
) )
), ),
tabPanel("Test de Krustal-Wallis", tabPanel("Test de Krustal-Wallis",
DT::dataTableOutput("kw_table") fluidRow(
column(4,
wellPanel(
selectInput("var_expliquees_kw","Choisir la variable à expliquer",multiple = FALSE,choices = NULL),
selectInput("var_explicatives_kw","Choisir les variables explicatives",multiple = TRUE,choices = NULL),
actionButton("kw_button", "ANOVA",class="btn-primary")
),
),
column(8,
wellPanel(
style = 'overflow-x: scroll;height: 650px;',
DT::dataTableOutput("kw_table"),
downloadButton("kw_button_download", "Télécharger le tableau",class="btn-primary")
),
)
)
), ),
tabPanel("Test de Fisher", tabPanel("Test de Fisher",
DT::dataTableOutput("fisher_table") DT::dataTableOutput("fisher_table")
@ -98,7 +146,8 @@ ui <- fluidPage(
wellPanel( wellPanel(
selectizeInput("khi2_cat","Choisir les variables",multiple = TRUE,choices = NULL), selectizeInput("khi2_cat","Choisir les variables",multiple = TRUE,choices = NULL),
actionButton("khi2_button", "KHI2",class="btn-primary") actionButton("khi2_button", "KHI2",class="btn-primary")
)), )
),
column(8, column(8,
wellPanel( wellPanel(
style = 'overflow-x: scroll;height: 650px;', style = 'overflow-x: scroll;height: 650px;',
@ -106,9 +155,7 @@ ui <- fluidPage(
downloadButton("khi2_button_download", "Télécharger le tableau",class="btn-primary") downloadButton("khi2_button_download", "Télécharger le tableau",class="btn-primary")
) )
) )
) )
), ),
tabPanel("Tous les tests", tabPanel("Tous les tests",
DT::dataTableOutput("test_table") DT::dataTableOutput("test_table")
@ -187,12 +234,9 @@ ui <- fluidPage(
) )
) )
), ),
), ),
) )
) )
server <- function(input, output, session) { server <- function(input, output, session) {
@ -200,9 +244,62 @@ server <- function(input, output, session) {
storage_mode = store_null() storage_mode = store_null()
) )
observe({
if(is.null(session$userData$authorize)) {
session$userData$authorize <- 0
}
})
observe({
# Vérifier si aucun paramètre n'est présent dans l'URL
if (!grepl("^[?&].*", session$clientData$url_search)) {
random_state <- toupper(paste0(sprintf("%02x", as.integer(random_bytes)), collapse = ""))
scope <- "openid profile"
auth_url <- sprintf("%s?client_id=%s&scope=%s&redirect_uri=%s&response_type=%s&state=%s",
authorize_url,client_id, scope, URLencode(uri_url), response_type, random_state)
jscommand <- sprintf("window.location.href ='%s';",auth_url)
print(jscommand)
runjs(jscommand)
} else if (grepl("\\bcode\\b", session$clientData$url_search)) {
authorization = base64enc::base64encode(charToRaw(paste0(client_id,":",client_secret)))
authorization = paste("Basic",authorization)
code=param_get(session$clientData$url_search,'code')[[1]]
body = list(
'grant_type' = 'authorization_code',
'redirect_uri' = 'http://localhost:8080',
'code' = code,
'state' = random_state
)
headers = c(
'Accept' = 'application/json',
'Content-Type' = 'application/x-www-form-urlencoded',
'Authorization' = authorization
)
res <- VERB("POST", url = "https://pcis.okta.com/oauth2/default/v1/token", body = body, add_headers(headers), encode = 'form')
if (res$status_code == 200){
res_content <- content(res,"parsed",encoding = "UTF-8")
headers2 = c("Authorization" = paste("Bearer",res_content$access_token))
res2 <- VERB("GET",url="https://pcis.okta.com/oauth2/default/v1/userinfo",add_headers(headers2))
print(res2)
name = content(res2, "parsed", encoding = "UTF-8")$name
output$welcome <- renderText({paste("Bonjour",name)})
session$userData$authorize = 1
} else {
print('Vous n avez pas l autorisation')
}
}
})
# Partie permettant de fusionner les fichiers # Partie permettant de fusionner les fichiers
observe({
if (session$userData$authorize == 0) {
shinyjs::runjs("shinyjs.hideAllElements();")
}
if (session$userData$authorize == 1) {
merged_data <- eventReactive(input$files, { merged_data <- eventReactive(input$files, {
# On lit la liste des fichiers et on les fusionne # On lit la liste des fichiers et on les fusionne
# Charger les données à partir des fichiers sélectionnés # Charger les données à partir des fichiers sélectionnés
@ -328,6 +425,10 @@ server <- function(input, output, session) {
choices = colnames( merged_data_type() %>% select_if(function(x) is.numeric(x) || is.integer(x)))) choices = colnames( merged_data_type() %>% select_if(function(x) is.numeric(x) || is.integer(x))))
updateSelectInput(session, "emmeans_explicatives", updateSelectInput(session, "emmeans_explicatives",
choices = colnames( merged_data_type() %>% select_if(function(x) is.factor(x)))) choices = colnames( merged_data_type() %>% select_if(function(x) is.factor(x))))
updateSelectInput(session, "var_expliquees_kw",
choices = colnames( merged_data_type() %>% select_if(function(x) is.numeric(x) || is.integer(x))))
updateSelectInput(session, "var_explicatives_kw",
choices = colnames( merged_data_type() %>% select_if(function(x) is.factor(x))))
updateSelectInput(session, "khi2_cat", updateSelectInput(session, "khi2_cat",
choices = colnames( merged_data_type() %>% select_if(function(x) is.factor(x)))) choices = colnames( merged_data_type() %>% select_if(function(x) is.factor(x))))
updateSelectInput(session, "khi2_num", updateSelectInput(session, "khi2_num",
@ -358,6 +459,11 @@ server <- function(input, output, session) {
return(input$var_expliquees) return(input$var_expliquees)
}) })
kw_explicative_col <- eventReactive(input$files,{
return(input$var_expliquees_kw)
})
#On utilise une fonction permettant d'obtenir la liste des différentes sources #On utilise une fonction permettant d'obtenir la liste des différentes sources
liste_source <- eventReactive(input$cat_id,{ liste_source <- eventReactive(input$cat_id,{
return(unique(merged_data()[[input$cat_id]])) return(unique(merged_data()[[input$cat_id]]))
@ -1017,7 +1123,8 @@ server <- function(input, output, session) {
return(test_table) return(test_table)
}) })
output$test_table <- renderDataTable(test_table(), output$test_table <- renderDataTable(
test_table(),
options = list( options = list(
pageLength = 10, pageLength = 10,
autoWidth = TRUE, autoWidth = TRUE,
@ -1188,7 +1295,8 @@ server <- function(input, output, session) {
}) })
}) })
}
} })
}
shinyApp(ui, server) shinyApp(ui, server)