-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimeseries.R
101 lines (87 loc) · 2.68 KB
/
timeseries.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
suppressWarnings(library(niivue))
library(shiny)
addResourcePath("images", "../images")
ui <- fluidPage(
tags$head(tags$style(HTML("body {background-color: #202020; color: white;}"))),
titlePanel("Time Series Demo"),
fluidRow(
splitLayout(
cellWidths = c("80%", "20%"),
tags$div(style = "width: 100%; height: 600px;", NiivueWidget$new()$plot),
tags$div(
tags$header(
checkboxInput("normalizeCheckbox", "Normalize Graph", value = FALSE),
actionButton("prevVolume", "Back"),
actionButton("nextVolume", "Forward"),
tags$div(
style = "margin-top: 5px;",
actionButton("animateButton", "Animate")
),
tags$div(
style = "margin-top: 5px;",
actionButton("saveButton", "Save Scene")
)
)
)
)
),
tags$footer(textOutput("locationString"))
)
server <- function(input, output, session) {
volumeList <- list(
list(url = "images/pcasl.nii.gz", colormap = "gray", opacity = 1, visible = TRUE, frame4D = 2)
)
nv <- NiivueWidget$new(list(
thumbnail = "images/pcasl.png",
onLocationChange = function(d) {
output$locationString <- renderText(d$string)
}
))
nv$setRadiologicalConvention(FALSE)
nv$loadVolumes(volumeList)
nv$setSliceType(SLICE_TYPE$MULTIPLANAR)
nv$graph$autoSizeMultiplanar <- TRUE
nv$opts$multiplanarForceRender <- TRUE
nv$graph$normalizeValues <- FALSE
nv$graph$opacity <- 1.0
currentVol <- 0
animationStatus <- reactiveVal(FALSE)
# normalize graph
observeEvent(input$normalizeCheckbox, {
nv$graph$normalizeValues <- input$normalizeCheckbox
}, ignoreInit = TRUE)
# goto previous volume
observeEvent(input$prevVolume, {
currentVol <<- max(currentVol - 1, 0)
nv$setFrame4D(nv$volumes[[1]]$id, currentVol)
}, ignoreInit = TRUE)
# goto next volume
observeEvent(input$nextVolume, {
currentVol <<- currentVol + 1
currentVol <<- min(currentVol, nv$getFrame4D(nv$volumes[[1]]$id) - 1)
nv$setFrame4D(nv$volumes[[1]]$id, currentVol)
}, ignoreInit = TRUE)
# loop volumes
observeEvent(input$animateButton, {
if (animationStatus()) {
animationStatus(FALSE)
} else {
animationStatus(TRUE)
}
}, ignoreInit = TRUE)
animationTimer <- reactiveTimer(100)
observe({
if (animationStatus()) {
animationTimer()
currentVol <<- currentVol + 1
if (currentVol >= nv$getFrame4D(nv$volumes[[1]]$id)) currentVol <<- 0
nv$setFrame4D(nv$volumes[[1]]$id, currentVol)
invalidateLater(100, session)
}
})
# save scene
observeEvent(input$saveButton, {
nv$saveScene()
}, ignoreInit = TRUE)
}
shinyApp(ui, server)