在Shiny应用程序中使用时,导致依赖性问题的不同d3版本

时间:2017-04-26 07:20:24

标签: r d3.js shiny dependencies

我试图在闪亮中加入三个图,所有图都使用d3库。在将它们放置在不同的tabPanel(或相同的那个)时,我只看到一个或两个图,它们没有正确反应。其中一个地块来自' pp.html'并基于d3.v3.min.js库。第二个情节是从“澳大利亚”'它使用d3.v4.js库。第三个图是使用R.的scatterD3库创建的。

下面给出了一个最低限度的工作示例:

ui.R

shinyUI(bootstrapPage(
      navbarPage("You Got Served!", id = "page",
      tabPanel("Overall Analysis", value = "panel1",
                  h2(textOutput("title")),
                  scatterD3Output("scatter", width = "1500", height = "700"),
                  br()),
      tabPanel("Parallel Coordinate", value = "panel2",
               fluidRow(
                   column(2, 
                          uiOutput("pc", width = 700, height = 600), 
                          br())
                 )),
      tabPanel("Sunburst", value= "panel3",
                          suppressDependencies("d3.v3.min.js"),
                          uiOutput("gs"),
                              br(),
                              hr())
)))

server.R

 shinyServer(function(input, output, session) {

 session$onSessionEnded({stopApp})
 output$scatter <- renderScatterD3({

   dat <- mydata %>%
     mutate(FirstServePercent = (w_1stIn/w_svpt) * 100, MatchDuration = 
minutes, Hand = winner_hand) %>%
     select(FirstServePercent, MatchDuration, Hand, Surface = surface, 
Tournament = tourney_name)

   s1 <- scatterD3(data = dat, y = FirstServePercent, x = MatchDuration, 
col_var = Surface, symbol_var = Hand, point_size = 70, labels_size = 30, 
xlab = "Match Duration (in minutes)", ylab = "First Serve %", axes_font_size 
= "15px", legend_font_size = '20', point_opacity = 0.5, hover_size = 1.8, 
hover_opacity = 1, transition = TRUE)

   s1
   })

 output$gs <- renderUI({
   return(htmlTemplate("australian.html"))})

 output$pc <- renderUI({

     return(htmlTemplate("pp.html"))})

})

我试图在R中找到与suppressDependencies()函数的用法相关的示例,但是找不到任何有效的示例。我想知道我应该在哪里使用该函数正确渲染三个图表及其相关的交互。如果解决方案涉及使用suppressDependencies以外的功能,我也非常感激。

数据集mydata的一部分看起来像这样:

mydata

1 个答案:

答案 0 :(得分:0)

您可以在renderUi中使用iframe来避免依赖性问题: plot是从'australian.html'中提取的,它使用d3.v4.js库。第三个图是使用R。

的scatterD3库创建的
output$gs <- renderUI({
    tags$iframe(src='australian.html',width="100%",frameBorder="0",heigh‌​t="500px")
})

output$pc <- renderUI({    
    tags$iframe(src='pp.html',width="100%",frameBorder="0",heigh‌​t="500px")    
})