# NOT RUN {
library(shiny)
ui <- fluidPage(
actionButton("add", "Add Data to y"),
echarts4rOutput("plot"),
h4("Brush"),
verbatimTextOutput("selected"),
h4("Legend select change"),
verbatimTextOutput("legend")
)
server <- function(input, output, session){
data <- data.frame(x = rnorm(10, 5, 3), y = rnorm(10, 50, 12), z = rnorm(10, 50, 5))
react <- eventReactive(input$add, {
set.seed(sample(1:1000, 1))
data.frame(x = rnorm(10, 5, 2), y = rnorm(10, 50, 10), z = rnorm(10, 1, 5))
})
output$plot <- renderEcharts4r({
data %>%
e_charts(x) %>%
e_scatter(y, z) %>%
e_scatter(z) %>%
e_brush()
})
observeEvent(input$add, {
echarts4rProxy("plot") %>%
e_append2_p(0, react(), x, y, z)
})
output$selected <- renderPrint({
input$plot_brush
})
output$legend <- renderPrint({
input$plot_legend_change
})
}
shinyApp(ui, server)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab