Using 2 HTML widgets in 1 r shiny application

155 views
Skip to first unread message

Radhikesh Ranadive

unread,
May 22, 2017, 4:10:22 PM5/22/17
to Shiny - Web Framework for R
Hello all,

I have posted this question on stack overflow community (link) but didn't got any response. So, thought of posting it here again. 

I have created two htmlwidgets using d3. I am trying to use both of them in the same shiny application, but I am able to use only one at a time. Please see the reproducible example below:


#library(devtools)
#install_github('radhikesh/d3Histogram')
#install_github('radhikesh/d3WordCloudWidget')

library(shiny)
library(d3Histogram)
library(d3WordCloudWidget)


ui <- shinyUI(fluidPage(

fluidRow(
column(width = 6, d3HistogramOutput("d3Hist"))),
fluidRow(
column(2, d3WordCloudWidgetOutput(
  "d3Cloud", width = "80%", height = 600
)))
))


server <- shinyServer(function(input, output) {

output$d3Hist <- renderD3Histogram({ 

dataset <- data.frame(lpu = c('Apple','Banana','Orange'), amount = 
c(20,10,15))
d3Histogram(dataset = dataset)

})

output$d3Cloud <- renderd3WordCloudWidget({

dm1 <-data.frame(Var1 = c('Apple','Banana','Orange'), Freq = c(20,10,15))    
dm1$Var1 <- as.character(dm1$Var1)
d3WordCloudWidget(dm1$Var1, dm1$Freq)

})
})

# Run the application 
shinyApp(ui = ui, server = server)


When testing my reproducible example, please comment any one of the output in the ui section d3HistogramOutput or d3WordCloudWidgetOutput and you can see that only one of the widget works at a same time.

Any help would be very much appreciated!

Thanks!


Radhikesh

 



Joe Cheng

unread,
May 22, 2017, 9:26:46 PM5/22/17
to Radhikesh Ranadive, Shiny - Web Framework for R
This part of your d3WordCloudWidget.yaml is wrong:

- name: d3
  version: 3.5.3
  src: htmlwidgets/lib/d3
  script: 
          - d3.js
          - d3.layout.cloud.js

Here you're saying that d3.layout.cloud.js is part of d3. But your other widget provides d3 without this JS file. In htmltools/htmlwidgets, if two dependencies have the same name and same version, they are assumed to be substitutes, and one of them is chosen while the other is discarded.

To solve this, in your .yaml file, make a second dependency named "d3cloud" or whatever and move d3.layout.cloud.js (and nothing else) into it. Make sure that the d3 dependency is listed before d3cloud.

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/4af2b245-75f0-4f23-b84c-8d7875ce4a3c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Radhikesh Ranadive

unread,
May 23, 2017, 9:46:27 AM5/23/17
to Shiny - Web Framework for R, rradh...@gmail.com
Thank you Joe, your suggestion worked for me. :)
Reply all
Reply to author
Forward
0 new messages