简体   繁体   English

在1个闪亮的应用程序中使用2个HTML小部件

[英]Using 2 HTML widgets in 1 r shiny application

This question is already asked here, ( Using 2 htmlwidgets in 1 R-Shiny Application ). 这个问题已经在这里提出( 在1个R-Shiny应用程序中使用2个htmlwidgets )。 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. 我已经使用d3创建了两个htmlwidget。 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. 在测试我的可复制示例时,请在ui部分d3HistogramOutput或d3WordCloudWidgetOutput中注释任何输出,您可以看到只有一个小部件可以同时工作。

Any help would be very much appreciated! 任何帮助将不胜感激!

Thanks! 谢谢!

I posted this question on R shiny's google group. 我在R Shin的Google组上发布了这个问题。 And got the solution that worked for me. 并找到了对我有用的解决方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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