Skip to content

Commit 519ee47

Browse files
update several shinyapps
1 parent 0d6bd50 commit 519ee47

File tree

6 files changed

+88
-43
lines changed

6 files changed

+88
-43
lines changed

inst/shiny/B04Sa_micmen/app.R

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
learndown::learndownShinyVersion("1.0.0")
1+
learndown::learndownShinyVersion("1.1.0")
22
conf <- BioDataScience::config()
33

44
library(shiny)
@@ -15,6 +15,11 @@ model_data <- tibble::tibble(
1515
y = SSmicmen(x, Vm = vm_init, K = k_init) +
1616
rnorm(n = length(x), sd = error_sd))
1717

18+
graph <- chart::chart(model_data, y ~ x) +
19+
ggplot2::geom_point() +
20+
ggplot2::xlab("x") +
21+
ggplot2::ylab("y")
22+
1823
ui <- fluidPage(
1924
learndownShiny("Ajustement manuel d'un modèle : Michaelis-Menten"),
2025

@@ -26,7 +31,7 @@ ui <- fluidPage(
2631
sliderInput("vm", label = "Vm",
2732
value = 1, min = 0, max = 10, step = 0.5),
2833
sliderInput("k", label = "K",
29-
value = 1, min = 0, max = 10, step = 0.5),
34+
value = 1, min = -3, max = 10, step = 0.5),
3035
hr(),
3136
submitQuitButtons()
3237
),
@@ -71,12 +76,13 @@ server <- function(input, output, session) {
7176

7277
output$model_plot <- renderPlot({
7378
data <- model_predict()
79+
p <- graph
7480

75-
chart::chart(data, y ~ x) +
76-
ggplot2::geom_point() +
77-
ggplot2::geom_line(chart::f_aes(y_predit ~ x), color = "red") +
78-
ggplot2::xlab("x") +
79-
ggplot2::ylab("y")
81+
if(!any(is.nan(data$y_predit))) {
82+
p <- p +
83+
ggplot2::geom_line(chart::f_aes(y_predit ~ x), color = "red", data = data)
84+
}
85+
p
8086
})
8187

8288
trackEvents(session, input, output,

inst/shiny/B04Sb_exponent/app.R

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
learndown::learndownShinyVersion("1.0.1")
1+
learndown::learndownShinyVersion("1.1.0")
22
conf <- BioDataScience::config()
33

44
library(shiny)
@@ -18,6 +18,11 @@ model_data <- tibble::tibble(
1818
y = exponent(x, y0 = y0_init, k = k_init) +
1919
rnorm(n = length(x), sd = error_sd))
2020

21+
graph <- chart::chart(model_data, y ~ x) +
22+
ggplot2::geom_point() +
23+
ggplot2::xlab("x") +
24+
ggplot2::ylab("y")
25+
2126
ui <- fluidPage(
2227
learndownShiny("Ajustement manuel d'un modèle : courbe exponentielle"),
2328

@@ -73,12 +78,14 @@ server <- function(input, output, session) {
7378

7479
output$model_plot <- renderPlot({
7580
data <- model_predict()
81+
p <- graph
82+
83+
if(!any(is.nan(data$y_predit))) {
84+
p <- p +
85+
ggplot2::geom_line(chart::f_aes(y_predit ~ x), color = "red", data = data)
86+
}
7687

77-
chart::chart(data, y ~ x) +
78-
ggplot2::geom_point() +
79-
ggplot2::geom_line(chart::f_aes(y_predit ~ x), color = "red") +
80-
ggplot2::xlab("x") +
81-
ggplot2::ylab("y")
88+
p
8289
})
8390

8491
trackEvents(session, input, output,

inst/shiny/B04Sc_logis/app.R

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
learndown::learndownShinyVersion("1.0.0")
1+
learndown::learndownShinyVersion("1.1.0")
22
conf <- BioDataScience::config()
33

44
library(shiny)
@@ -16,6 +16,11 @@ model_data <- tibble::tibble(
1616
y = SSlogis(x, Asym = asym_init, xmid = xmid_init, scal = scal_init) +
1717
rnorm(n = length(x), sd = error_sd))
1818

19+
graph <- chart::chart(model_data, y ~ x) +
20+
ggplot2::geom_point() +
21+
ggplot2::xlab("x") +
22+
ggplot2::ylab("y")
23+
1924
ui <- fluidPage(
2025
learndownShiny("Ajustement manuel d'un modèle : courbe logistique"),
2126

@@ -29,7 +34,7 @@ ui <- fluidPage(
2934
sliderInput("xmid", label = "Xmid",
3035
value = 1.00, min = 0.25, max = 10.00, step = 0.25),
3136
sliderInput("scal", label = "Scal",
32-
value = 1.00, min = 0.25, max = 10.00, step = 0.25),
37+
value = 1.00, min = -2.00, max = 6.00, step = 0.25),
3338

3439
hr(),
3540

@@ -79,17 +84,18 @@ server <- function(input, output, session) {
7984

8085
output$model_plot <- renderPlot({
8186
data <- model_predict()
87+
p <- graph
8288

83-
chart::chart(data, y ~ x) +
84-
ggplot2::geom_point() +
85-
ggplot2::geom_line(chart::f_aes(y_predit ~ x), color = "red") +
86-
ggplot2::xlab("x") +
87-
ggplot2::ylab("y")
89+
if(!any(is.nan(data$y_predit))) {
90+
p <- p +
91+
ggplot2::geom_line(chart::f_aes(y_predit ~ x), color = "red", data = data)
92+
}
93+
p
8894
})
8995

9096
trackEvents(session, input, output,
9197
sign_in.fun = BioDataScience::sign_in, config = conf)
92-
trackSubmit(session, input, output, max_score = 2, solution =
98+
trackSubmit(session, input, output, max_score = 3, solution =
9399
list(asym = asym_init, xmid = xmid_init, scal = scal_init),
94100
comment = "y = asym/1+e(xmid-x/scal)",
95101
message.success = "Correct, c'est le meilleur modèle.",

inst/shiny/B04Sd_gen_logis/app.R

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
learndown::learndownShinyVersion("1.0.0")
1+
learndown::learndownShinyVersion("1.2.0")
22
conf <- BioDataScience::config()
33

44
library(shiny)
@@ -18,6 +18,11 @@ model_data <- tibble::tibble(
1818
y = SSfpl(x, A = a_init, B = b_init, xmid = xmid_init, scal = scal_init) +
1919
rnorm(n = length(x), sd = error_sd))
2020

21+
graph <- chart::chart(model_data, y ~ x) +
22+
ggplot2::geom_point() +
23+
ggplot2::xlab("x") +
24+
ggplot2::ylab("y")
25+
2126
ui <- fluidPage(
2227
learndownShiny("Ajustement manuel d'un modèle : modèle logistique généralisé"),
2328

@@ -33,7 +38,7 @@ ui <- fluidPage(
3338
sliderInput("xmid", label = "Xmid",
3439
value = 1.00, min = 0.25, max = 10.00, step = 0.25),
3540
sliderInput("scal", label = "Scal",
36-
value = 1.00, min = 0.25, max = 10.00, step = 0.25),
41+
value = 1.00, min = -1.00, max = 5.00, step = 0.25),
3742
hr(),
3843
submitQuitButtons()
3944
),
@@ -82,12 +87,13 @@ server <- function(input, output, session) {
8287

8388
output$model_plot <- renderPlot({
8489
data <- model_predict()
90+
p <- graph
8591

86-
chart::chart(data, y ~ x) +
87-
ggplot2::geom_point() +
88-
ggplot2::geom_line(chart::f_aes(y_predit ~ x), color = "red") +
89-
ggplot2::xlab("x") +
90-
ggplot2::ylab("y")
92+
if(!any(is.nan(data$y_predit))) {
93+
p <- p +
94+
ggplot2::geom_line(chart::f_aes(y_predit ~ x), color = "red", data = data)
95+
}
96+
p
9197
})
9298

9399
trackEvents(session, input, output,

inst/shiny/B04Se_gompertz/app.R

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
learndown::learndownShinyVersion("1.0.0")
1+
learndown::learndownShinyVersion("1.2.1")
22
conf <- BioDataScience::config()
33

44
library(shiny)
@@ -17,6 +17,11 @@ model_data <- tibble::tibble(
1717
y = SSgompertz(x, Asym = asym_init, b2 = b2_init, b3 = b3_init) +
1818
rnorm(n = length(x), sd = error_sd))
1919

20+
graph <- chart::chart(model_data, y ~ x) +
21+
ggplot2::geom_point() +
22+
ggplot2::xlab("x") +
23+
ggplot2::ylab("y")
24+
2025
ui <- fluidPage(
2126
learndownShiny("Ajustement manuel d'un modèle : modèle de Gompertz"),
2227

@@ -30,7 +35,7 @@ ui <- fluidPage(
3035
sliderInput("b2", label = "b2",
3136
value = 1.00, min = 0, max = 10.00, step = 0.5),
3237
sliderInput("b3", label = "b3",
33-
value = 1.00, min = -2.00, max = 2.00, step = 0.25),
38+
value = 1.00, min = -1.00, max = 2.00, step = 0.25),
3439
hr(),
3540
submitQuitButtons()
3641
),
@@ -58,6 +63,7 @@ ui <- fluidPage(
5863
server <- function(input, output, session) {
5964

6065
model_predict <- reactive({
66+
6167
dplyr::mutate(model_data,
6268
y_predit = SSgompertz(x, Asym = input$asym, b2 = input$b2, b3 = input$b3),
6369
distance2 = (y_predit - y)^2
@@ -77,12 +83,20 @@ server <- function(input, output, session) {
7783

7884
output$model_plot <- renderPlot({
7985
data <- model_predict()
80-
81-
chart::chart(data, y ~ x) +
82-
ggplot2::geom_point() +
83-
ggplot2::geom_line(chart::f_aes(y_predit ~ x), color = "red") +
84-
ggplot2::xlab("x") +
85-
ggplot2::ylab("y")
86+
p <- graph
87+
88+
if(!any(is.nan(data$y_predit))) {
89+
p <- p +
90+
ggplot2::geom_line(chart::f_aes(y_predit ~ x), color = "red", data = data)
91+
}
92+
93+
# if(any(is.nan(data$y_predit))) {
94+
# p <- graph
95+
# } else {
96+
# p <- graph +
97+
# ggplot2::geom_line(chart::f_aes(y_predit ~ x), color = "red", data = data)
98+
# }
99+
p
86100
})
87101

88102
trackEvents(session, input, output,

inst/shiny/B04Sf_richards/app.R

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
learndown::learndownShinyVersion("0.0.1")
1+
learndown::learndownShinyVersion("1.1.0")
22
conf <- BioDataScience::config()
33

44
library(shiny)
@@ -20,8 +20,13 @@ model_data <- tibble::tibble(
2020
y = richards(x, Asym = asym_init, lrc = lrc_init, c0 = c0_init, m = m_init) +
2121
rnorm(n = length(x), sd = error_sd))
2222

23+
graph <- chart::chart(model_data, y ~ x) +
24+
ggplot2::geom_point() +
25+
ggplot2::xlab("x") +
26+
ggplot2::ylab("y")
27+
2328
ui <- fluidPage(
24-
learndownShiny("Ajustement manuel d'un modèle : modèle de Weibull"),
29+
learndownShiny("Ajustement manuel d'un modèle : modèle de Richards"),
2530

2631
sidebarLayout(
2732
sidebarPanel(
@@ -83,12 +88,13 @@ server <- function(input, output, session) {
8388

8489
output$model_plot <- renderPlot({
8590
data <- model_predict()
91+
p <- graph
8692

87-
chart::chart(data, y ~ x) +
88-
ggplot2::geom_point() +
89-
ggplot2::geom_line(chart::f_aes(y_predit ~ x), color = "red") +
90-
ggplot2::xlab("x") +
91-
ggplot2::ylab("y")
93+
if(!any(is.nan(data$y_predit))) {
94+
p <- p +
95+
ggplot2::geom_line(chart::f_aes(y_predit ~ x), color = "red", data = data)
96+
}
97+
p
9298
})
9399

94100
trackEvents(session, input, output,

0 commit comments

Comments
 (0)