Commit ec444baf authored by Falipou Eva's avatar Falipou Eva
Browse files

Version fonctionnelle du code avec : importation d'un fichier csv, sélection...

Version fonctionnelle du code avec : importation d'un fichier csv, sélection des différents paramètres à étudier et affichage des résultats calculés par le modèle ln-linéaire généralisé.
No related merge requests found
Showing with 100 additions and 145 deletions
+100 -145
......@@ -5,105 +5,6 @@ library(rhandsontable)
library(data.table)
library(numDeriv)
# UI
ui <- fluidPage(
# App title ----
titlePanel("Generalized ln-linear"),
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
h3("Create data table"),
# Input: ----
fileInput("file1", "Choose csv file with semicolon separator",
multiple = FALSE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv")),
uiOutput("var_ui"),
#selectInput("var","Select parameter:",choices=c("MES"="MES","DCO"="DCO","DBO5"="DBO5","NK"="NK","NNH4"="NNH4","NNO3"="NNO3")),
numericInput("LQ", "Quantification limit of the selected parameter", min=0, value=1),
numericInput("nbcov", "Number of explanatory variable modalities", min=1, value=2, max=10),
rHandsontableOutput("tabEdit"), # affichage de la table a editer
actionButton("go", "Create"),
br(),
br(),
br(),
h3("Effects on median"),
uiOutput("choose_median"),
h3("Effects on dispersion"),
uiOutput("choose_disp"),
h3("Choose quantile (%)"),
numericInput("alpha", "Quantile", min=1, value=50, max=100),
actionButton("run", "Show results")),
# Main panel for displaying outputs ----
mainPanel(
tabsetPanel(type="tabs",
tabPanel("Tutorial",
h3("How to use the Generalized ln-linear Shiny App"),
br(),
p(strong("> Select the csv file containing the data to be analyzed")),
p("It has to be a csv file with semicolon separator"),
br(),
p(strong("> Choose the dependent variable")),
p("For example TSS"),
br(),
p(strong("> State the value of the corresponding quantification limit")),
p("For example 2.0 (mg/L) for TSS"),
br(),
p(strong("> Indicate the number of explanatory variable modalities to be investigated")),
p("Other than those corresponding to the reference set"),
br(),
p(strong("> Complete the table describing each explanatory variable modality with the following information:")),
p("- the label of the modality that you want to see in the different results tables",em("(for example 'inf2ans')")),
p("- the column header in your csv file corresponding to the explanatory variable",em("(for example 'classe_age')")),
p("- the expression of the modality inside this column in your csv file",em("(for example '< 2 ans')")),
br(),
p(strong("> Click on the 'Create' button and then check in the 'Data Table' panel if the table is well-built")),
br(),
p(strong("> Choose the modalities to consider in order to evaluate their effets on median and dispersion")),
br(),
p(strong("> Choose the quantile you want to be returned by the model")),
br(),
p(strong("> Lauch the model by clicking on the 'Show results' button. The table of estimates and the table of quantiles appear in the 'Results' panel."))
),
tabPanel("Data Table",
textOutput("lab_don"),
tableOutput("don")),
tabPanel("Results",
h3("> Table of estimates"),
textOutput("lab_res"),
dataTableOutput("test"),
h3("> Quantiles"),
textOutput("lab_quant"),
dataTableOutput("quantile"))
)
)
)
)
ln_lineaire <- function(labvdep,don,zm,zd,alpha){
nbzm <- length(zm);
......@@ -409,9 +310,109 @@ ln_lineaire <- function(labvdep,don,zm,zd,alpha){
}
# UI
ui <- fluidPage(
# App title ----
titlePanel("Generalized ln-linear"),
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
h3("Create data table"),
# Input: ----
fileInput("file1", "Choose csv file with semicolon separator",
multiple = FALSE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv")),
uiOutput("var_ui"),
numericInput("LQ", "Quantification limit of the selected parameter", min=0, value=1),
numericInput("nbcov", "Number of explanatory variable modalities", min=1, value=2, max=10),
rHandsontableOutput("tabEdit"), # affichage de la table a editer
actionButton("go", "Create"),
br(),
br(),
br(),
h3("Effects on median"),
uiOutput("choose_median"),
h3("Effects on dispersion"),
uiOutput("choose_disp"),
h3("Choose quantile (%)"),
numericInput("alpha", "Quantile", min=1, value=50, max=100),
actionButton("run", "Show results")),
# Main panel for displaying outputs ----
mainPanel(
tabsetPanel(type="tabs",
tabPanel("Tutorial",
h3("How to use the Generalized ln-linear Shiny App"),
br(),
p(strong("> Select the csv file containing the data to be analyzed")),
p("It has to be a csv file with semicolon separator"),
br(),
p(strong("> Choose the dependent variable")),
p("For example TSS"),
br(),
p(strong("> State the value of the corresponding quantification limit")),
p("For example 2.0 (mg/L) for TSS"),
br(),
p(strong("> Indicate the number of explanatory variable modalities to be investigated")),
p("Other than those corresponding to the reference set"),
br(),
p(strong("> Complete the table describing each explanatory variable modality with the following information:")),
p("- the label of the modality that you want to see in the different results tables",em("(for example 'inf2ans')")),
p("- the column header in your csv file corresponding to the explanatory variable",em("(for example 'classe_age')")),
p("- the expression of the modality inside this column in your csv file",em("(for example '< 2 ans')")),
br(),
p(strong("> Click on the 'Create' button and then check in the 'Data Table' panel if the table is well-built")),
br(),
p(strong("> Choose the modalities to consider in order to evaluate their effets on median and dispersion")),
br(),
p(strong("> Choose the quantile you want to be returned by the model")),
br(),
p(strong("> Lauch the model by clicking on the 'Show results' button. The table of estimates and the table of quantiles appear in the 'Results' panel."))
),
tabPanel("Data Table",
textOutput("lab_don"),
tableOutput("don")),
tabPanel("Results",
h3("> Table of estimates"),
textOutput("lab_res"),
dataTableOutput("test"),
h3("> Quantiles"),
textOutput("lab_quant"),
dataTableOutput("quantile"))
)
)
)
)
# server
server <- function(input, output) {
values <- reactiveValues(mat=NULL, don=NULL)
# Importation du fichier de donnees
data <- reactive({
req(input$file1)
......@@ -433,7 +434,6 @@ server <- function(input, output) {
})
# Selection covariables
values <- reactiveValues(mat=NULL, don=NULL)
observe({
if (!is.null(input$tabEdit))
values$mat <- hot_to_r(input$tabEdit)
......@@ -453,48 +453,6 @@ server <- function(input, output) {
## Creation de la DataTable don
# don <- eventReactive(input$go, {
#
# dt <- cbind(data(),y=data()[input$var])
# colnames(dt)[ncol(dt)] <- "y"
#
# # Left-censoring
# loq <- input$LQ
#
# dt <- cbind(dt,lb=data()[input$var])
# colnames(dt)[ncol(dt)] <- "lb"
# dt$lb[dt$y <= loq] <- 0
#
# dt <- cbind(dt,ub=data()[input$var])
# colnames(dt)[ncol(dt)] <- "ub"
# dt$ub[dt$y <= loq] <- loq
#
# ## Covariates ##
# dt <- as.data.table(dt)
# for (i in 1:input$nbcov){
# dt[,values$mat[i,1]:=ifelse(get(values$mat[i,2])==values$mat[i,3],1,0)]
# }
#
# ## Nettoyage ##
# dt <- select(dt, -1:-(grep("y",colnames(dt))-1))
# dt <- na.omit(dt)
#
# # Effects on location (median) and dispersion
# output$choose_median <- renderUI({
# checkboxGroupInput("median","Effects on median", choices = values$mat[,1],selected = values$mat[,1])
# })
#
# output$choose_disp <- renderUI({
# checkboxGroupInput("disp","Effects on dispersion", choices = values$mat[,1],selected = values$mat[,1])
# })
#
# output$lab_don <- renderText({
# paste("Parameter: ",isolate(input$var),"\n")
# })
#
# dt
# })
observeEvent(input$go, {
don <- cbind(data(),y=data()[input$var])
......@@ -538,15 +496,12 @@ server <- function(input, output) {
})
})
#output$don <- renderTable(don()) #verification don
output$don <- renderTable(values$don) #verification don
## Lancement modele
observeEvent(input$run,{
#outputs <- ln_lineaire(labvdep=input$var,don=don(),zm=input$median,zd=input$disp,alpha=input$alpha/100)
outputs <- ln_lineaire(labvdep=input$var,don=values$don,zm=input$median,zd=input$disp,alpha=input$alpha/100)
# return table of estimates
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment