-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathplot_scatter.R
More file actions
83 lines (75 loc) · 2.42 KB
/
plot_scatter.R
File metadata and controls
83 lines (75 loc) · 2.42 KB
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
plot_scatter_module_ui <- function(id) {
ns <- shiny::NS(id)
tagList(
sliderInput(ns("sample"), "Number of pixels", min = 100, max = 10000, value = 1000),
radioButtons(ns("axis"), "x axis", choices = c("Longitude", "Latitude")),
actionButton(ns("run"), "Plot scatterplot", icon = icon("arrow-turn-down")),
downloadButton(ns("download"), "Download plot")
)
}
plot_scatter_module_server <- function(id, common, parent_session, map) {
moduleServer(id, function(input, output, session) {
shinyjs::hide("download")
observeEvent(input$run, {
# WARNING ####
if (is.null(common$raster)) {
common$logger |> writeLog(type = "error", "Please load a raster file")
return()
}
# FUNCTION CALL ####
raster_name <- c(common$meta$select_query$name, common$meta$select_async$name, common$meta$select_user$name)
scatterplot <- plot_scatter(common$raster, input$sample, input$axis, raster_name)
# LOAD INTO SPP ####
common$scatterplot <- scatterplot
# METADATA ####
common$meta$plot_scatter$axis <- input$axis
common$meta$plot_scatter$sample <- input$sample
common$meta$plot_scatter$name <- raster_name
# TRIGGER ####
trigger("plot_scatter")
show_results(parent_session)
shinyjs::show("download")
})
output$result <- renderPlot({
watch("plot_scatter")
req(common$scatterplot)
common$scatterplot()
})
output$download <- downloadHandler(
filename = function() {
"shinyscholar_scatterplot.png"
},
content = function(file) {
png(file, width = 1000, height = 500)
common$scatterplot()
dev.off()
})
return(list(
save = function() {list(
### Manual save start
### Manual save end
sample = input$sample,
axis = input$axis)
},
load = function(state) {
### Manual load start
### Manual load end
updateSliderInput(session, "sample", value = state$sample)
updateRadioButtons(session, "axis", selected = state$axis)
}
))
}
)}
plot_scatter_module_result <- function(id) {
ns <- NS(id)
# Result UI
plotOutput(ns("result"))
}
plot_scatter_module_rmd <- function(common) {
# Variables used in the module's Rmd code
list(
plot_scatter_knit = !is.null(common$scatterplot),
plot_scatter_axis = common$meta$plot_scatter$axis,
plot_scatter_sample = common$meta$plot_scatter$sample,
plot_scatter_name = common$meta$plot_scatter$name)
}