Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working with echarts4r #5

Closed
etiennebacher opened this issue Oct 28, 2021 · 2 comments
Closed

Not working with echarts4r #5

etiennebacher opened this issue Oct 28, 2021 · 2 comments

Comments

@etiennebacher
Copy link
Owner

library(shiny)
library(prompter)
library(echarts4r)
library(magrittr)

ui <- fluidPage(
  use_prompt(),
  br(),
  actionButton(
    "bs4_color_info",
    "bs4_color_info",
    class="btn-info",
    style = "color: white"
  ),
  column(
    9,
    br(),
    echarts4rOutput("plot") %>% 
      add_prompt(
        message = "The color is different of bs4_color_success button",
        position = "top", 
        type = "info", 
        size = "medium", 
        rounded = TRUE
      )
    
      
  )
)

server <- function(input, output, session) {
  output$plot <- renderEcharts4r({
    mtcars %>% e_charts(mpg) %>% e_scatter(drat)
  })
}

shinyApp(ui, server)
Error in if (ui_element$name == "img") { : argument is of length zero
@etiennebacher
Copy link
Owner Author

Works well with plotly, it must be a problem with how echarts creates a canvas (+ a problem with add_prompt()):

library(shiny)
library(prompter)
library(echarts4r)
library(plotly)
library(magrittr)

ui <- fluidPage(
  use_prompt(),
  br(),
  actionButton(
    "bs4_color_info",
    "bs4_color_info",
    class="btn-info",
    style = "color: white"
  ),
  column(
    9,
    br(),
    tags$div(
      class="hint--bottom hint--info hint--medium hint--rounded",
      `aria-label`="The color is different of bs4_color_success button",
      plotlyOutput("plot") 
    )
   
      
  )
)

server <- function(input, output, session) {
  output$plot <- renderPlotly({
    plot_ly(economics, x = ~date, y = ~pop)
  })
}

shinyApp(ui, server)

@etiennebacher
Copy link
Owner Author

This was partially fixed in 9a0187b but I referenced the wrong issue in the commit. There is still a problem with the dimensions of echarts plot. What I understand is that echarts scales the plot with the dimensions of the parent div, which here is the div with hint. Therefore, the 100% width that echarts applies are the 100% width of the div with hint, which is quite narrow.
Possible to change the dimensions of echarts manually but I don't like that, it seems too hacky / not robust.

library(shiny)
library(echarts4r)
library(magrittr)

ui <- fluidPage(
  use_prompt(),
  br(),
  actionButton(
    "bs4_color_info",
    "bs4_color_info",
    class="btn-info",
    style = "color: white"
  ),
  column(
    9,
    br(),
    echarts4rOutput("plot", width = "600px") %>% 
      add_prompt(
        message = "The color is different of bs4_color_success button",
        position = "bottom",
        type = "info",
        size = "medium",
        rounded = TRUE
      )
    
      
  )
)

server <- function(input, output, session) {
  output$plot <- renderEcharts4r({
    mtcars %>% e_charts(mpg) %>% e_scatter(drat)
  })
}

shinyApp(ui, server)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant