Created
October 2, 2021 03:09
-
-
Save helgasoft/fe675678e83d8816a16aea3c87fe28ea to your computer and use it in GitHub Desktop.
R | ECharts | dynamic resize with echarty
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://echarts.apache.org/en/api.html#echartsInstance.resize | |
| # https://echarts.apache.org/examples/en/editor.html?c=line-easing | |
| library(shiny); library(dplyr); library(echarty) | |
| ui <- fluidPage( titlePanel("Resize with echarty"), | |
| fluidRow(ecs.output('chart')), | |
| checkboxInput('toggle900','Toggle Size 900px'), | |
| checkboxInput('toggle400','Toggle Size 400px') | |
| ) | |
| server <- function(input, output) { | |
| output$chart <- ecs.render({ | |
| # add column color | |
| tmp <- data.frame(Species = as.vector(unique(iris$Species)), | |
| color = c("#387e78","#eeb422","#d9534f")) | |
| df <- iris %>% inner_join(tmp) | |
| p <- df %>% group_by(Species) %>% ec.init() | |
| p$x$opts$xAxis <- list(name='Sepal.Length', nameLocation='center') | |
| p$x$opts$yAxis <- list(name='Sepal.Width', nameRotate=90, nameLocation='center') | |
| p | |
| }) | |
| observeEvent(input$toggle400, { | |
| p <- ecs.proxy('chart') | |
| val <- if (input$toggle400) 400 else 'auto' | |
| p$x$opts <- list( resizeOpts=list(width=val, height=val, | |
| animation = list(duration= 2000, easing= 'linear')) ) | |
| p %>% ecs.exec('p_resize') | |
| }) | |
| observeEvent(input$toggle900, { | |
| p <- ecs.proxy('chart') | |
| val <- if (input$toggle900) 900 else 'auto' | |
| p$x$opts <- list( resizeOpts=list(width=val, height=val, | |
| animation = list(duration= 2000, easing= 'elasticOut')) ) | |
| p %>% ecs.exec('p_resize') | |
| }) | |
| ecs.output("chart") | |
| } | |
| shinyApp(ui = ui, server = server) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Apparently - no
category to category axes - yes