r2d3上的输出条形图不显示图形

时间:2019-02-11 13:43:05

标签: javascript r shiny dplyr shinydashboard

我正在尝试使用r2d3绘制条形图。目的是绘制按产品分组的产品数量(产品1的2个单位,产品2的3个单位,...)。产品名称的列名称为:名称。

问题是,当我运行闪亮的应用程序时,它不会绘制图形,而只是显示:错误:找不到变量bar_plot。

想法来自此帖子: enter link description here

代码如下:

con <- dbConnect(odbc(), 
                 Driver = "SQL Server", 
                 Server = "MyServer", 
                 Database = "MyDB", 
                 Trusted_Connection = "True")


# get the products table
products = tbl(con, 'products')


dashboardBody(
    
    tabsetPanel(
      
      id = "tabs",
      
      tabPanel(
        
        title = "Main Dashboard",
        
        value = "page1",
        
        fluidRow(
          
          valueBoxOutput("total_products")
          
        ),
        fluidRow(),
        
        fluidRow(
          column(
            width = 6,
            d3Output("group_totals")
            
 # several parenthesis here           
            
 output$group_totals <- renderD3({
    
     products %>%
      group_by(name) %>%
      tally() %>%
      collect() %>%
      arrange(desc(n)) %>%
      head(10) %>%
      rename(
        x = name,
        y = n,
        label = name
      ) %>%
      
      r2d3("bar_plot.js")
    
  })

0 个答案:

没有答案