ProcessanimateR animation can be also used interactively as part of a
(Shiny) web-application. Here,
an example application that expects attributes are of an appropriate
data type and automatically chooses appropriate color scales is given.
We first define a function ianimate_process
that defines
our Shiny application as follows:
library(processanimateR)
library(shiny)
library(shinycssloaders)
<- function(eventlog, min.time = 30, max.time = 600, default.time = 60) {
ianimate_process
<- function(request) {
ui fluidPage(
$head(tags$style("#process{height:90vh !important;}")),
tagstitlePanel("Hello processanimateR!"),
sidebarLayout(
sidebarPanel(
width = 2,
sliderInput("duration", "Animation duration", min.time, max.time, default.time),
selectInput("type", "Animation type", c("relative", "absolute"), "relative"),
selectInput("sizeAttribute", "Size attribute", c("none", colnames(eventlog)), "none"),
selectInput("colorAttribute", "Color attribute", c("none", colnames(eventlog)), "none"),
selectInput("orientation", "Orientation", c("horizontal"="LR", "vertical"="TB"), "horizontal"),
h4("Selected cases"),
textOutput("token_selection"),
h4("Selected activities"),
textOutput("activity_selection")
),
mainPanel(
width = 10,
::withSpinner(processanimaterOutput("process"))
shinycssloaders
)
)
)
}
<- function(session, input, output) {
server
<- reactive({
data
if (input$colorAttribute != "none") {
<- rlang::sym(input$colorAttribute)
attr <- eventlog %>% pull(!!attr)
val if (!(is.character(val) || is.factor(val))) {
warning("Trying to use a numeric attribute for the token color!")
}
}
if (input$sizeAttribute != "none") {
# This only works for numeric attributes
<- rlang::sym(input$sizeAttribute)
attr <- eventlog %>% pull(!!attr)
val if (!is.numeric(val)) {
warning("Trying to use a non-numeric attribute for the token size!")
}
}
eventlog
})
$token_selection <- renderText({
output
paste0(input$process_tokens, ",")
})
$activity_selection <- renderText({
output
paste0(input$process_activities, ",")
})
$process <- renderProcessanimater(expr = {
output<- processmapR::process_map(data(), render = F)
graph <- DiagrammeR::add_global_graph_attrs(graph, attr = "rankdir", value = input$orientation, attr_type = "graph")
model if (input$sizeAttribute != "none" && input$colorAttribute != "none") {
animate_process(data(), model,
mode = input$type,
legend = "color",
mapping = token_aes(color = token_scale(input$colorAttribute, scale = "ordinal",
range = RColorBrewer::brewer.pal(5, "YlOrBr")),
size = token_scale(input$sizeAttribute, scale = "linear", range = c(6,10))),
duration = input$duration)
else if (input$sizeAttribute != "none") {
} animate_process(data(), model,
mode = input$type,
legend = "size",
mapping = token_aes(size = token_scale(input$sizeAttribute, scale = "linear", range = c(6,10))),
duration = input$duration)
else if (input$colorAttribute != "none") {
} animate_process(data(), model,
mode = input$type,
legend = "color",
mapping = token_aes(color = token_scale(input$colorAttribute, scale = "ordinal", range = RColorBrewer::brewer.pal(5, "YlOrBr"))),
duration = input$duration)
else {
} animate_process(data(), model,
mode = input$type,
duration = input$duration)
}
})
}
shinyApp(ui, server, options = list(height = 500))
}
Then, the application can be, for example, launched by calling:
library(eventdataR)
library(edeaR)
library(dplyr)
ianimate_process(sepsis %>%
filter_trace_frequency(percentage = 0.2) %>%
filter_activity(c("Return ER"), reverse = T) %>%
# we fix the datatype of some of the attributes to allow proper rendering of the token color
# the token size option currently only support numeric attributes
mutate_at(c("lacticacid", "leucocytes", "crp", "age"), as.numeric) %>%
mutate_at(c("disfuncorg", "sirscriteria2ormore", "infectionsuspected"), as.logical))