ProjectMOSAIC / mosaicCalc

Calculus in R
12 stars 4 forks source link

integrateODE() not looking in correct environment on shinyapps.io #8

Open dtkaplan opened 3 years ago

dtkaplan commented 3 years ago

This code, run in a learnr exercise on desktop, works fine. But on shinyapps.io, it doesn't work. The problem on shinyapps.io can be worked around by using <<- for the first few definitions. This suggests to me that integrateODE() isn't looking in the right environment when functions are defined outside the argument list. This might go as far back as D() or even makeFun().

f <- rfun( ~ x + y, seed=103)
dx_f <- D(f(x, y) ~ x)
dy_f <- D(f(x, y) ~ y)
soln1 <- integrateODE(dx ~ dx_f(x=x, y=y), 
                     dy ~ dy_f(x=x, y=y), 
                     x = 1, y = -3,
                     tdur = list(from=0, to=10, dt=0.1))
soln2 <- integrateODE(dx ~ -dx_f(x=x, y=y), 
                     dy ~ -dy_f(x=x, y=y), 
                     x = -2, y = 0.75,
                     tdur = list(from=0, to=10, dt=0.1))

contour_plot(f(x, y) ~ x + y, domain(x=c(-5, 5), y=c(-5, 5))) %>%
  gradient_plot(f(x, y) ~ x + y) %>%
  traj_plot(y(t) ~ x(t), soln1, color="blue") %>%
  traj_plot(y(t) ~ x(t), soln2, color="red")