Overview

Description

Create a Shiny application for longitudinal data model.

Usage

shinymlx(model, parameter=NULL, output=NULL, treatment=NULL, data=NULL, style="basic", appname="shinymlxApp", title=" ", settings=NULL,)

Arguments

model
a Mlxtran or PharmML model used for the simulation.
parameter
a vector, or a list of shiny widgets
output
a list with fields
treatment
a list with fields
Remark: Input argument of Simulx can also be used, i.e. a list with fields time, amount, rate, tinf, type, target.
data
a datafile to display with the plot
title
the title of the application
appname
the name of the application (and possibly its path)
style
the style of the Shiny app
settings
a list of settings

Value

A directory tempdir with files ui.R, server.R and model.txt


Examples

Example 1: introductory example


R script: doc_shinymlx1.R


We want to compare zero-order and first-order absorption processes for a single dose administration.

The model is implemented as an inline model:

model1 <- inlineModel("
[LONGITUDINAL]
input = {ka, Tk0, V, k}

EQUATION:
D  = 100

if t>Tk0
  f0=D/(V*Tk0*k)*(1-exp(-k*Tk0))*exp(-k*(t-Tk0))
else
  f0=D/(V*Tk0*k)*(1-exp(-k*t))
end

f1 = f0
f2 = D*ka/(V*(ka-k))*(exp(-k*t) - exp(-ka*t))
")

Let us start using simulx for computing and plotting \(f_1\) and \(f_2\)

library(reshape2)
f <- list(name = c('f1','f2'), time = seq(0, 20, 0.1))

p <- c(ka=0.5, Tk0=2, V=10, k=0.2)

r <- simulx(model = model1, parameter = p, output = f)

r <- melt(merge(r$f1,r$f2),  id='time', variable.name='f')
ggplot(r, aes(time,value)) + geom_line(aes(colour = f),size=1) +
  guides(colour=guide_legend(title=NULL)) +theme(legend.position=c(.9, .75))

We can now run shinymlx with the same input arguments. Sliders will be automatically created for the 4 parameters. By default, the minimum and maximum values of a slider are the value of the parameter multiplied, respectively, by 0.5 and 2. The step is the range (max-min) divided by 15.

shiny.app <- shinymlx(model = model1, parameter = p, output = f)
shiny::runApp(shiny.app)

It is possible to customize the widgets used for each parameters. Available widgets are “slider”, “numeric” (enter a numerical value) and “select” (select between possible choices). No widget will be created by defining widget=“none”.

In the example below, A slider is created for \(ka\), a numeric input control for \(Tk0\) and a select list input control for \(k\). \(V=10\) is constant.

By default, style = “basic” is used to create a basic application. Other styles are available, including “dashboard1” to create a Shiny dashboard. You can then, for instance, tick the checkbox Reference to display a reference curve (i.e. which is not modified when you modify the parameters values) or reset this reference curve. You can also select the outputs to be displayed, select which variable use for the x-axis, use a log scale for the y-axis, display the R codes, the model code…

p <- list( ka  = list(widget='slider',  value=0.5,min=0.1,max=1,step=0.1),
           Tk0 = list(widget='numeric', value=2),
           V   = list(widget='none',    value=2),
           k   = list(widget='select',  selected=0.2, choices=c(0.05,0.2,0.4))
)
shiny.app <- shinymlx(model=model1, parameter=p, output=f, style="dashboard1", 
                      title="Compare PK models")
shiny::runApp(shiny.app)



Several display settings can be modified (see the shinymlx help for the list of display settings). In the example below, the list of variables available for the x-axis and the log scale option are not displayed.

Using style = “navbar1” will create a Shiny application with a navigation bar and 2 tabPanels: the parameters and the outputs.

s <- list(select.x=FALSE, select.log=FALSE)
shiny.app <- shinymlx(model=model1, parameter=p, output=f, style="navbar1", settings=s)
shiny::runApp(shiny.app)



Using style = “navbar2” will create a Shiny application with the widgets and the output options side-by-side.

shiny.app <- shinymlx(model=model1, parameter=p, output=f, style="navbar2", settings=s)
shiny::runApp(shiny.app)



Example 2: load and display data


R script: doc_shinymlx2.R


in this example, we want to display the predicted concentration provided by a model together with some PK data.

Data is stored in the file data/pkdata1.txt:

[LONGITUDINAL]
time  y
0.5    0.451
1      0.552
2       0.676
4       0.568
6       0.334
8       0.205
12    0.126
16    0.187
20    0.098
24    0.043

We can then select this datafile with the input argument data and plot the data.

Note that in this example, each parameter is defined as a vector of length 4: then a slider will be automatically created for each of these parameters, using the information in the vector: (value, min, max, step).

myModel <- inlineModel("
[LONGITUDINAL]
input = {ka, V, Cl}
EQUATION:
C = pkmodel(ka, V, Cl)
")

f <- list(name = 'C', 
          time = c(0, 25, 0.5))

p <- list( ka = c(0.5,0.25,3,0.25),
           V  = c(5,1,20,1),
           Cl = c(1,0.5,3,.1))

shiny.app <- shinymlx(model     = myModel,
                      data      = 'data/pkdata1.txt',
                      treatment = list(time=c(0,12), amount=c(10,3)),
                      parameter = p, 
                      output    = f)
shiny::runApp(shiny.app)



Example 3: PK model - combine multiple administrations


R script: doc_shinymlx3.R


In this example, we consider a basic one compartment PK model. Here, input argument treatment is defined as a combination of oral and iv administrations, as it would be defined for simulx.

We may also want to modify the dosage regimen interactively. We thus define the time of first dose (tfd), the number of doses (nd) and the interdose interval (ii). We create sliders for these parameters, for the amount and for the rate of infusion by defining for each a vector (value, minimum, maximum, step). We can also interactively modify the route of administration by creating a list of possible values for type: 1=oral, 2=iv.

Two panels are then created for the two types of administration: adm1 and adm2. The parameters of the model can still be modified in the panel param

myModel <- inlineModel("
[LONGITUDINAL]
input = {F, ka, V, k}

PK:
depot(type=1, target=Ad, p=F)
depot(type=2, target=Ac)

EQUATION:
ddt_Ad = -ka*Ad
ddt_Ac =  ka*Ad - k*Ac
Cc = Ac/V
")

p    <- c(F=0.7, ka=1, V=10, k=0.1)
Cc   <- list(name="Cc", time=seq(0, 100, by=0.1))

adm1 <- list(
  type   = list(widget="select", selected=1, choices=c(1,2)),
  tfd    = list(widget="slider", value=6,  min=0, max=24, step=2),
  nd     = list(widget="slider", value=3,  min=0, max=10, step=1),
  ii     = list(widget="slider", value=12, min=3, max=24, step=1),
  amount = list(widget="slider", value=40, min=0, max=50, step=5)
)
adm2 <- list(
  type   = list(widget="select", selected=2, choices=c(1,2)),
  tfd    = list(widget="slider", value=12, min=0, max=24, step=2),
  nd     = list(widget="slider", value=2,  min=0, max=10, step=1),
  ii     = list(widget="slider", value=30, min=6, max=60, step=6),
  amount = list(widget="slider", value=20, min=0, max=50, step=5),
  rate   = list(widget="slider", value=5,  min=1, max=10, step=1)
)

shiny.app <- shinymlx(model   = myModel,
                      parameter = p,
                      output    = Cc,
                      treatment = list(adm1,adm2),
                      style     = "navbar1")
shiny::runApp(shiny.app)


Example 4: PKPD model - display multiple outputs


R script: doc_shinymlx4.R
PKPDmodel <- inlineModel("
[LONGITUDINAL] 
input={ka,V,Cl,ke0,Imax,IC50,S0,kout}

EQUATION:
{Cc, Ce}  = pkmodel(ka, V, Cl, ke0)

Ec = Imax*Cc/(Cc+IC50)
E1 = S0*(1 - Ec)

Ee = Imax*Ce/(Ce+IC50)
E2 = S0*(1 - Ee)

E3_0 = S0 
ddt_E3 = kout*((1-Ec)*S0- E3)  
")

pk.param <- c(ka=0.5, V=10, Cl=1)
pd.param <- c(ke0=0.1, Imax=0.5, IC50=0.03, S0=100, kout=0.1)

adm <- list(tfd=5, nd=15, ii=12, amount=1)

pk <- list(name = 'Cc',                time = seq(0, 250, by=1))
pd <- list(name = c('E1','E2', 'E3'),  time = seq(0, 250, by=1))


shiny.app <- shinymlx(model     = PKPDmodel, 
                      treatment = adm,
                      parameter = list(pk.param, pd.param), 
                      output    = list(pk, pd),
                      title     = "PKPD models",
                      style     = "dashboard1",
                      appname   = "demo4")
shiny::runApp(shiny.app)