Skip to content

Commit 43dde41

Browse files
add shiny app on Michaelis-Menten models
1 parent 6ec1aa7 commit 43dde41

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#
2+
# This is the server logic of a Shiny web application. You can run the
3+
# application by clicking 'Run App' above.
4+
#
5+
# Find out more about building applications with Shiny here:
6+
#
7+
# http://shiny.rstudio.com/
8+
#
9+
10+
library(shiny)
11+
SciViews::R()
12+
13+
# Define server logic required to draw a histogram
14+
shinyServer(function(input, output) {
15+
16+
output$trees_plot <- renderPlot({
17+
18+
set.seed(42)
19+
micmen_exo <- tibble(
20+
conc = seq(0, 25, by = 0.1),
21+
vitesse = SSmicmen(conc, Vm = 6, K = 2) + rnorm(n = length(conc), sd = 0.05),
22+
vit_predit = SSmicmen(conc, Vm = input$vm_ui, K = input$k_ui)
23+
)
24+
25+
chart::chart(micmen_exo, vitesse ~ conc) +
26+
ggplot2::geom_point() +
27+
geom_line(f_aes(vit_predit ~ conc), color = "red") +
28+
xlab("Concentration [mol/L]") +
29+
ylab("Vitesse [mol/min]")
30+
})
31+
32+
output$micmen_model <- renderUI({
33+
withMathJax(
34+
sprintf("Ton modèle : $$Vitesse \\ = \\frac{%.02f* concentration}{%.02f + concentration}$$",
35+
input$vm_ui, input$k_ui))
36+
})
37+
38+
39+
output$micmen_resid <- renderUI({
40+
set.seed(42)
41+
micmen_exo <- tibble(
42+
conc = seq(0, 25, by = 0.1),
43+
vitesse = SSmicmen(conc, Vm = 6, K = 2) + rnorm(n = length(conc), sd = 0.05),
44+
vit_predit = SSmicmen(conc, Vm = input$vm_ui, K = input$k_ui),
45+
distance2 = (vit_predit - vitesse)^2
46+
)
47+
48+
value <- sum(micmen_exo$distance2)
49+
50+
withMathJax(
51+
sprintf("La valeur de la somme des résidus au carré de ton modèle : $$%.05f$$",
52+
value))
53+
})
54+
55+
56+
output$micmen_theo <- renderPlot({
57+
58+
micmen_data <- tibble(
59+
conc = seq(0, 15, by = 0.1),
60+
v = SSmicmen(conc, Vm = 1, K = 0.5)
61+
)
62+
63+
chart(data = micmen_data, v ~ conc) +
64+
geom_line() +
65+
labs( x = "x [input]", y = "y") +
66+
geom_vline(xintercept = 0, col = "darkgray") +
67+
geom_hline(yintercept = c(0.5, 1), col = "gray", linetype = "dashed") +
68+
geom_vline(xintercept = 0.4, col = "gray", linetype = "dashed") +
69+
annotate("text", label = "Vm", x = -0.4, y = 1) +
70+
annotate("text", label = "Vm/2", x = -0.5, y = 0.55) +
71+
annotate("text", label = "K", x = 0.5, y = 0.04)
72+
})
73+
74+
})

inst/shiny/04a_michaelis_menten/ui.R

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
library(shiny)
2+
3+
titlePanel_h4 <- function(title, windowTitle = title) {
4+
tagList(tags$head(tags$title(windowTitle)), h4(title))
5+
}
6+
7+
# Define UI for application that draws a histogram
8+
shinyUI(
9+
navbarPage(
10+
title = titlePanel_h4("Modèle de Michaelis-Menten"),
11+
tabPanel(
12+
"Un peu de théorie",
13+
sidebarLayout(
14+
sidebarPanel(
15+
withMathJax(),
16+
h4("Le Contexte"),
17+
p("La courbe de Michaelis-Menten est bien connue pour modéliser des
18+
cinétiques chimiques simples, enzymatiques en particulier."),
19+
h4("L'équation mathématique :"),
20+
p("$$\\frac{V_{m} * input}{K + input}$$"),
21+
h4("Eléments importants :"),
22+
p("- une asymptote horizontale qui correspond à la vitesse
23+
maximale asymptotique de la réaction"),
24+
hr(),
25+
h4("La fonction dans R : "),
26+
p("$$SSmicmen(input, Vm, K)$$"),
27+
h5("Arguments de la fonction : "),
28+
p("Vm : est la vitesse maximale de la réaction"),
29+
p("K : est la valeur de x pour la Vm/2"),
30+
width = 5
31+
),
32+
mainPanel(
33+
p("Le graphique ci-dessous représente un modèle Michaelis-Menten avec
34+
Vm = 1 et K = 0.4. Le trait horizontal en Vm = 1 représente la
35+
vitesse maximale possible (asymptote horizontale du modèle)."),
36+
plotOutput("micmen_theo"),
37+
width = 7
38+
)
39+
)
40+
),
41+
tabPanel(
42+
title = "A toi de jouer !",
43+
sidebarLayout(
44+
sidebarPanel(
45+
withMathJax(),
46+
p("La courbe de Michaelis-Menten permet de modéliser des cinétiques
47+
chimiques simple. Nous pouvons utiliser la fonction
48+
SSmicmen(input, Vm, K) dans R."),
49+
p("L'équation mathématique de la fonction est la
50+
suivante: $$\\frac{V_{m} * input}{K + input}$$"),
51+
numericInput(inputId = "vm_ui", label = "Valeur de Vm",
52+
value = 1.00, min = 0.50, max = 10.00, step = 0.5),
53+
p("Valeur par défaut : 1 "),
54+
numericInput(inputId = "k_ui", label = "Valeur de K",
55+
value = 1.00, min = 0.50, max = 10.00, step = 0.5),
56+
p("Valeur par défaut : 1 ")
57+
),
58+
mainPanel(
59+
h4("Ajustez le meilleur modèle de Michaelis-Menten"),
60+
p("Vous devez ajuster votre modèle en faisant varier les
61+
paramètres du modèle."),
62+
plotOutput("trees_plot"),
63+
hr(),
64+
withMathJax(),
65+
uiOutput("micmen_model"),
66+
hr(),
67+
uiOutput("micmen_resid"),
68+
hr()
69+
)
70+
)
71+
)
72+
)
73+
)

0 commit comments

Comments
 (0)