简体   繁体   中英

Using 2 HTML widgets in 1 r shiny application

This question is already asked here, ( Using 2 htmlwidgets in 1 R-Shiny Application ). I am facing the same problem and couldn't find the solution for this, so posting it as a new question with reproducible example.

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!

I posted this question on R shiny's google group. And got the solution that worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM