selection for types with labels
This commit is contained in:
parent
98b09d2f93
commit
4823f7a630
|
@ -17,6 +17,17 @@ ui <- fluidPage(
|
|||
apexchartOutput("chart2"),
|
||||
verbatimTextOutput("result2")
|
||||
)
|
||||
),
|
||||
fluidRow(
|
||||
column(
|
||||
width = 6,
|
||||
tags$b("Pie selection"),
|
||||
apexchartOutput("chart3"),
|
||||
verbatimTextOutput("result3")
|
||||
),
|
||||
column(
|
||||
width = 6
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -46,6 +57,18 @@ server <- function(input, output, session) {
|
|||
input$month_click_mult
|
||||
})
|
||||
|
||||
output$chart3 <- renderApexchart({
|
||||
data.frame(
|
||||
answer = c("Yes", "No"),
|
||||
n = c(254, 238)
|
||||
) %>%
|
||||
apex(type = "pie", mapping = aes(x = answer, y = n)) %>%
|
||||
set_input_category("click_pie")
|
||||
})
|
||||
output$result3 <- renderPrint({
|
||||
input$click_pie
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
shinyApp(ui, server)
|
|
@ -36,10 +36,19 @@ HTMLWidgets.widget({
|
|||
}
|
||||
if (x.input.hasOwnProperty("category")) {
|
||||
ax_opts.chart.events.dataPointSelection = function(event, chartContext, opts) {
|
||||
var data = opts.w.config.series[opts.seriesIndex].data;
|
||||
var selected = opts.selectedDataPoints[0].map(function(index) {
|
||||
return data[index].x;
|
||||
});
|
||||
var typeLabels = ["pie", "radialBar", "donut"];
|
||||
var selected;
|
||||
if (typeLabels.indexOf(opts.w.config.chart.type) > -1) {
|
||||
var labels = opts.w.config.labels;
|
||||
selected = opts.selectedDataPoints[0].map(function(index) {
|
||||
return labels[index];
|
||||
});
|
||||
} else {
|
||||
var data = opts.w.config.series[opts.seriesIndex].data;
|
||||
selected = opts.selectedDataPoints[0].map(function(index) {
|
||||
return data[index].x;
|
||||
});
|
||||
}
|
||||
Shiny.setInputValue(
|
||||
x.input.category.inputId,
|
||||
selected
|
||||
|
|
Loading…
Reference in New Issue