You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
4.7 KiB
112 lines
4.7 KiB
|
|
|
|
colUI <- function(id) {
|
|
ns <- NS(id)
|
|
tagList(highchartOutput(ns("colchart")))
|
|
}
|
|
|
|
colServer <-
|
|
function(id,
|
|
dat,
|
|
name= "Inputs",
|
|
ytitle="Number of Entries",
|
|
maintitle="",
|
|
caption="",
|
|
filename="Inputs") {
|
|
moduleServer(id,
|
|
function(input, output, session) {
|
|
ns <- session$ns
|
|
|
|
|
|
if(length(unique(dat$Country))==1){
|
|
output$colchart <- renderHighchart({
|
|
|
|
dat |>
|
|
hchart(type="column", hcaes(x = Input_data,
|
|
y = Observations), name=name) |>
|
|
hc_plotOptions(
|
|
series = list(
|
|
showInLegend = FALSE,
|
|
pointFormat = "{point.y}",
|
|
colorByPoint = TRUE,
|
|
dataLabels = list(enabled = TRUE)
|
|
)
|
|
|
|
) |>
|
|
# Axis
|
|
hc_yAxis(
|
|
title = list(text = ytitle),
|
|
labels = list(format = "{value}")
|
|
) |>
|
|
hc_xAxis(categories = dat$Input_data) |>
|
|
# Titles, subtitle, caption and credits
|
|
hc_title(text = maintitle) |>
|
|
#hc_subtitle(text = paste("Total", total, sep = " ")) |>
|
|
hc_caption(text = caption) |>
|
|
hc_credits(
|
|
enabled = TRUE,
|
|
text = "LaNubia Consulting",
|
|
href = "https://www.lanubia.com",
|
|
style = list(fontSize = "12px")
|
|
) |>
|
|
hc_exporting(
|
|
enabled = TRUE, # always enabled
|
|
filename = filename
|
|
)
|
|
})
|
|
}
|
|
|
|
if(length(unique(dat$Country))>1){
|
|
output$colchart <- renderHighchart({
|
|
# print(dat)
|
|
input.summary<-dat
|
|
|
|
input.summary.summ <- input.summary |>
|
|
group_by(Input_data) |>
|
|
summarise(Observations = sum(Observations)) |>
|
|
arrange(desc(Observations))
|
|
|
|
input.summary.drilldown <- input.summary |>
|
|
group_nest(Input_data) |>
|
|
mutate(
|
|
id = Input_data,
|
|
type = "column",
|
|
data = map(data, mutate, name = Country, y = Observations),
|
|
data = map(data, list_parse)
|
|
)
|
|
tt <-
|
|
tooltip_table(c("No. of Observations(Input)"), c("{point.Observations}"))
|
|
hchart(
|
|
input.summary.summ,
|
|
"column",
|
|
hcaes(
|
|
x = Input_data,
|
|
y = Observations,
|
|
name = Input_data,
|
|
drilldown = Input_data
|
|
),
|
|
name = "Segment view",
|
|
colorByPoint = TRUE
|
|
) |>
|
|
hc_drilldown(allowPointDrilldown = TRUE,
|
|
series = list_parse(input.summary.drilldown)) |>
|
|
hc_tooltip(pointFormat = tt,
|
|
# "{point.name} {point.pop}"
|
|
useHTML = TRUE,
|
|
valueDecimals = 0) |>
|
|
hc_yAxis(title = list(text = "Number of observations")) |>
|
|
hc_xAxis(title = "Segment") |>
|
|
hc_credits(enabled = TRUE,
|
|
text = "LaNubia Data Science",
|
|
href = "https://www.lanubia.com/") |>
|
|
hc_exporting(enabled = TRUE, # always enabled
|
|
filename = "Input Summary") |>
|
|
hc_title(text = "Observations by segment") |>
|
|
hc_subtitle(text = "Click on the bar to view details by country")
|
|
})
|
|
}
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|