Skip to content

issues when rendering an r2d3-based package's plots in shiny #99

@feddelegrand7

Description

@feddelegrand7

Hi,

Thank you for the great package. It's really a breeze to integrate D3 with R. In this context, I've developed a small package that outputs some D3 basic plots. Unfortunately, when I tried to use the package in shiny using D3output and renderD3, I encountered the following issue:

  • When modifying a Shiny Input, which the D3 plot relies on, the D3 plot is again rendered (which is perfect), but instead of getting a new plot, I get an overlay of the old plot and new plot(s). What's also interesting is that when I resize the window, the old plots disappear and I get only the last one. (See example below).

The plots generated by ddplot are normal D3.js graphics, so in my understanding it should work normally in Shiny. Do you have an idea please, maybe I'm using the r2d3 API wrongly.

Thanks in advance :)

library(shiny)
library(r2d3)
library(ddplot)

ui <- fluidPage(
  inputPanel(
    sliderInput("bar_max", label = "Max:",
      min = 0, max = 100, value = 1, step = 1)
  ),
  d3Output("plot")
)

server <- function(input, output) {
  
  
  output$plot <- renderD3({
    
    barChart(
      data  = mtcars,
      x = "am", 
      y = "mpg", 
      fill = "red",
      yticks = input$bar_max
    )
  })
}

shinyApp(ui = ui, server = server)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions