if (interactive()) {
library(shiny)
ui <- fluidPage(
fluidRow(
column(
width = 8, offset = 2,
tags$h2("Apexchart in Shiny"),
apexchartOutput("chart"),
verbatimTextOutput(outputId = "res_click")
)
)
)
server <- function(input, output, session) {
output$chart <- renderApexchart({
apexchart() %>%
ax_chart(
type = "bar",
events = events_opts(
dataPointSelection = JS(
"function(event, chartContext, config) {
Shiny.setInputValue('click', config.selectedDataPoints)
}"
)
)
) %>%
ax_series(
list(
name = "Example",
data = sample(1:100, 5)
)
) %>%
ax_xaxis(
categories = LETTERS[1:5]
)
})
output$res_click <- renderPrint({
input$click
})
}
shinyApp(ui, server)
}
Run the code above in your browser using DataLab