Skip to content

Commit 6716fdc

Browse files
rename shinyapps
1 parent 39142af commit 6716fdc

4 files changed

Lines changed: 385 additions & 0 deletions

File tree

inst/shiny/B01Sa_reglin/app.R

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
learndown::learndownShinyVersion("1.0.0")
2+
conf <- BioDataScience::config()
3+
4+
library(shiny)
5+
library(learndown)
6+
library(BioDataScience2)
7+
8+
a_init <- -1.5
9+
b_init <- 3.5
10+
error_sd <- 0.25
11+
set.seed(42)
12+
13+
reglin <- function(x, a, b)
14+
(a * x) + b
15+
16+
model_data <- tibble::tibble(
17+
x = seq(0, 10, by = 0.25),
18+
y = reglin(x, a = a_init, b = b_init) +
19+
rnorm(n = length(x), sd = error_sd))
20+
21+
ui <- fluidPage(
22+
learndownShiny("Ajustement manuel d'un modèle : régression linéaire"),
23+
24+
sidebarLayout(
25+
sidebarPanel(
26+
withMathJax(),
27+
p("$$y(x) = a \\ x + \\ b $$"),
28+
sliderInput("a", label = "a",
29+
value = 0, min = -5, max = 5, step = 0.5),
30+
sliderInput("b", label = "b",
31+
value = 0, min = -5, max = 5, step = 0.5),
32+
hr(),
33+
submitQuitButtons()
34+
),
35+
36+
mainPanel(
37+
plotOutput("model_plot"),
38+
hr(),
39+
withMathJax(),
40+
fluidRow(
41+
column(width = 6,
42+
p("Modèle paramétré :"),
43+
uiOutput("model_equation")),
44+
column(width = 6,
45+
p("Somme des carrés des résidus (valeur à minimiser) :"),
46+
uiOutput("model_resid"))
47+
)
48+
)
49+
)
50+
)
51+
52+
53+
server <- function(input, output, session) {
54+
55+
model_predict <- reactive({
56+
dplyr::mutate(model_data,
57+
y_predit = reglin(x, a = input$a, b = input$b),
58+
distance2 = (y_predit - y)^2
59+
)
60+
})
61+
62+
output$model_equation <- renderUI({
63+
withMathJax(
64+
sprintf("$$y(x) \\ = %.02f \\ x + \\ %.02f$$",
65+
input$a, input$b))
66+
})
67+
68+
output$model_resid <- renderUI({
69+
data <- model_predict()
70+
withMathJax(sprintf("$$ \\ %.02f \\ $$", sum(data$distance2)))
71+
})
72+
73+
output$model_plot <- renderPlot({
74+
data <- model_predict()
75+
76+
chart::chart(data, y ~ x) +
77+
ggplot2::geom_point() +
78+
ggplot2::geom_line(chart::f_aes(y_predit ~ x), color = "red") +
79+
ggplot2::xlab("x") +
80+
ggplot2::ylab("y")
81+
})
82+
83+
trackEvents(session, input, output,
84+
sign_in.fun = BioDataScience::sign_in, conf = conf)
85+
trackSubmit(session, input, output, max_score = 2,
86+
solution = list(a = a_init, b = b_init),
87+
comment = "y = a.x + b",
88+
message.success = "Correct, c'est le meilleur modèle. a est la pente et b est l'ordonnée à l'origine de la droite.",
89+
message.error = "Incorrect, un modèle mieux ajusté existe.")
90+
trackQuit(session, input, output, delay = 20)
91+
}
92+
93+
shinyApp(ui, server)

inst/shiny/B04Sa_micmen/app.R

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
learndown::learndownShinyVersion("0.0.9000")
2+
conf <- BioDataScience::config()
3+
4+
library(shiny)
5+
library(learndown)
6+
7+
vm_init <- 6
8+
k_init <- 2
9+
error_sd <- 0.05
10+
set.seed(42)
11+
12+
model_data <- tibble::tibble(
13+
x = seq(0, 25, by = 0.1),
14+
y = SSmicmen(x, Vm = vm_init, K = k_init) +
15+
rnorm(n = length(x), sd = error_sd))
16+
17+
ui <- fluidPage(
18+
learndownShiny("Ajustement manuel d'un modèle : Michaelis-Menten"),
19+
20+
sidebarLayout(
21+
sidebarPanel(
22+
withMathJax(),
23+
p("$$y(x) = \\frac{V_{m} * x}{K + x}$$"),
24+
25+
sliderInput("vm", label = "Vm",
26+
value = 1, min = 0, max = 10, step = 0.5),
27+
sliderInput("k", label = "K",
28+
value = 1, min = 0, max = 10, step = 0.5),
29+
30+
hr(),
31+
32+
submitQuitButtons()
33+
),
34+
35+
mainPanel(
36+
plotOutput("model_plot"),
37+
38+
hr(),
39+
40+
withMathJax(),
41+
fluidRow(
42+
column(width = 6,
43+
p("Modèle paramétré :"),
44+
uiOutput("model_equation")),
45+
46+
column(width = 6,
47+
p("Somme des carrés des résidus (valeur à minimiser) :"),
48+
uiOutput("model_resid"))
49+
)
50+
)
51+
)
52+
)
53+
54+
55+
server <- function(input, output, session) {
56+
57+
58+
model_predict <- reactive({
59+
dplyr::mutate(model_data,
60+
y_predit = SSmicmen(x, Vm = input$vm, K = input$k),
61+
distance2 = (y_predit - y)^2
62+
)
63+
})
64+
65+
output$model_equation <- renderUI({
66+
withMathJax(
67+
sprintf("$$y(x) = \\frac{%.02f * x}{%.02f + x}$$",
68+
input$vm, input$k))
69+
})
70+
71+
output$model_resid <- renderUI({
72+
data <- model_predict()
73+
withMathJax(sprintf("$$ \\ %.02f \\ $$", sum(data$distance2)))
74+
})
75+
76+
output$model_plot <- renderPlot({
77+
data <- model_predict()
78+
79+
chart::chart(data, y ~ x) +
80+
ggplot2::geom_point() +
81+
ggplot2::geom_line(chart::f_aes(y_predit ~ x), color = "red") +
82+
ggplot2::xlab("x") +
83+
ggplot2::ylab("y")
84+
})
85+
86+
trackEvents(session, input, output,
87+
sign_in.fun = BioDataScience::sign_in, config = conf)
88+
trackSubmit(session, input, output, max_score = 2,
89+
solution = list(vm = vm_init, k = k_init),
90+
comment = "y = Vm*x/K+x",
91+
message.success = "Correct, c'est le meilleur modèle.",
92+
message.error = "Incorrect, un modèle mieux ajusté existe.")
93+
trackQuit(session, input, output, delay = 20)
94+
}
95+
96+
shinyApp(ui, server)

inst/shiny/B04Sb_exponent/app.R

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
learndown::learndownShinyVersion("0.0.9000")
2+
conf <- BioDataScience::config()
3+
4+
library(shiny)
5+
library(learndown)
6+
7+
y0_init <- 3.5
8+
k_init <- 0.10
9+
error_sd <- 0.5
10+
set.seed(42)
11+
12+
exponent <- function(x, y0, k)
13+
y0 * exp(k * x)
14+
15+
ui <- fluidPage(
16+
learndownShiny("Ajustement manuel d'un modèle : courbe exponentielle"),
17+
18+
sidebarLayout(
19+
sidebarPanel(
20+
withMathJax(),
21+
p("$$y(x) = y_0 \\ e^{k \\ x}$$"),
22+
23+
sliderInput("y0", label = "y0",
24+
value = 1, min = -5, max = 5, step = 0.5),
25+
sliderInput("k", label = "k",
26+
value = 0.025, min = -0.20, max = 0.20, step = 0.025),
27+
28+
hr(),
29+
submitQuitButtons()
30+
),
31+
32+
mainPanel(
33+
plotOutput("model_plot"),
34+
35+
hr(),
36+
37+
withMathJax(),
38+
fluidRow(
39+
column(width = 6,
40+
p("Modèle paramétré :"),
41+
uiOutput("model_equation")),
42+
43+
column(width = 6,
44+
p("Somme des carrés des résidus (valeur à minimiser) :"),
45+
uiOutput("model_resid"))
46+
)
47+
)
48+
)
49+
)
50+
51+
52+
server <- function(input, output, session) {
53+
54+
55+
model_data <- tibble::tibble(
56+
x = seq(0, 20, by = 0.5),
57+
y = exponent(x, y0 = y0_init, k = k_init) +
58+
rnorm(n = length(x), sd = error_sd))
59+
60+
model_predict <- reactive({
61+
dplyr::mutate(model_data,
62+
y_predit = exponent(x, y0 = input$y0, k = input$k),
63+
distance2 = (y_predit - y)^2
64+
)
65+
})
66+
67+
output$model_equation <- renderUI({
68+
withMathJax(
69+
sprintf("$$y(x) \\ = %.02f \\ e^{%.02f \\ x}$$", input$vm, input$k))
70+
})
71+
72+
output$model_resid <- renderUI({
73+
data <- model_predict()
74+
withMathJax(sprintf("$$ \\ %.02f \\ $$", sum(data$distance2)))
75+
})
76+
77+
output$model_plot <- renderPlot({
78+
data <- model_predict()
79+
80+
chart::chart(data, y ~ x) +
81+
ggplot2::geom_point() +
82+
ggplot2::geom_line(chart::f_aes(y_predit ~ x), color = "red") +
83+
ggplot2::xlab("x") +
84+
ggplot2::ylab("y")
85+
})
86+
87+
trackEvents(session, input, output,
88+
sign_in.fun = BioDataScience::sign_in, config = conf)
89+
trackSubmit(session, input, output, max_score = 2,
90+
solution = list(y0 = y0_init, k = k_init),
91+
comment = "y = y0.e^(k.x)",
92+
message.success = "Correct, c'est le meilleur modèle. y0 et la valeur de y pour x = 0 et k est la vitesse de croissance.",
93+
message.error = "Incorrect, un modèle mieux ajusté existe.")
94+
trackQuit(session, input, output, delay = 20)
95+
}
96+
97+
shinyApp(ui, server)

inst/shiny/B04Sc_logis/app.R

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
learndown::learndownShinyVersion("0.0.9000")
2+
conf <- BioDataScience::config()
3+
4+
library(shiny)
5+
library(learndown)
6+
7+
asym_init <- 5
8+
xmid_init <- 4
9+
scal_init <- 0.5
10+
error_sd <- 0.1
11+
set.seed(42)
12+
13+
model_data <- tibble::tibble(
14+
x = seq(0, 8, by = 0.1),
15+
y = SSlogis(x, Asym = asym_init, xmid = xmid_init, scal = scal_init) +
16+
rnorm(n = length(x), sd = error_sd))
17+
18+
ui <- fluidPage(
19+
learndownShiny("Ajustement manuel d'un modèle : courbe logistique"),
20+
21+
sidebarLayout(
22+
sidebarPanel(
23+
withMathJax(),
24+
p("$$y(x) = \\frac{Asym}{1 + e^{\\frac{xmid - x}{scal}}}$$"),
25+
26+
sliderInput("asym", label = "Asym",
27+
value = 1.00, min = 0.50, max = 10.00, step = 0.5),
28+
sliderInput("xmid", label = "Xmid",
29+
value = 1.00, min = 0.25, max = 10.00, step = 0.25),
30+
sliderInput("scal", label = "Scal",
31+
value = 1.00, min = 0.25, max = 10.00, step = 0.25),
32+
33+
hr(),
34+
35+
submitQuitButtons()
36+
),
37+
38+
mainPanel(
39+
plotOutput("model_plot"),
40+
41+
hr(),
42+
43+
withMathJax(),
44+
fluidRow(
45+
column(width = 6,
46+
p("Modèle paramétré :"),
47+
uiOutput("model_equation")),
48+
49+
column(width = 6,
50+
p("Somme des carrés des résidus (valeur à minimiser) :"),
51+
uiOutput("model_resid"))
52+
)
53+
)
54+
)
55+
)
56+
57+
58+
server <- function(input, output, session) {
59+
60+
model_predict <- reactive({
61+
dplyr::mutate(model_data,
62+
y_predit = SSlogis(x, Asym = input$asym, xmid = input$xmid,
63+
scal = input$scal),
64+
distance2 = (y_predit - y)^2
65+
)
66+
})
67+
68+
output$model_equation <- renderUI({
69+
withMathJax(
70+
sprintf("$$y(x) = \\frac{%.02f}{1 + e^{\\frac{%.02f - x}{%.02f}}}$$",
71+
input$asym, input$xmid, input$scal))
72+
})
73+
74+
output$model_resid <- renderUI({
75+
data <- model_predict()
76+
withMathJax(sprintf("$$ \\ %.02f \\ $$", sum(data$distance2)))
77+
})
78+
79+
output$model_plot <- renderPlot({
80+
data <- model_predict()
81+
82+
chart::chart(data, y ~ x) +
83+
ggplot2::geom_point() +
84+
ggplot2::geom_line(chart::f_aes(y_predit ~ x), color = "red") +
85+
ggplot2::xlab("x") +
86+
ggplot2::ylab("y")
87+
})
88+
89+
trackEvents(session, input, output,
90+
sign_in.fun = BioDataScience::sign_in, config = conf)
91+
trackSubmit(session, input, output, max_score = 2, solution =
92+
list(asym = asym_init, xmid = xmid_init, scal = scal_init),
93+
comment = "y = asym/1+e(xmid-x/scal)",
94+
message.success = "Correct, c'est le meilleur modèle.",
95+
message.error = "Incorrect, un modèle mieux ajusté existe.")
96+
trackQuit(session, input, output, delay = 20)
97+
}
98+
99+
shinyApp(ui, server)

0 commit comments

Comments
 (0)