ArulesVIZ interactive plot - Shiny R

1.1k Views Asked by At

I want to create a shiny web app for association mining. One of the thing I want to do is to implement an interactive plot from the package arulesVIZ.

So I have the following code:

    library(shiny)
    library(DT)
    library(data.table)
    library(arules)
    library(arulesViz)

    df_transac <-read.table("C:/Users/pauljacq/Desktop/splits/Association     files/ns_transactions.csv",header=T, sep=",")
    t<-read.transactions("C:/Users/pauljacq/Desktop/splits/Associationfiles/ns_transactions.csv", format='single',cols=c('shipment_archive_id','ASIN'),sep=",")

    rules_t <- apriori(t, 
               parameter = list(support = 0.0001, confidence = 0.0001, minlen=2, maxlen=5, ext=TRUE ), 
               control = list(verbose=TRUE))

    rules_table<-data.table(lhs=labels(lhs(rules_t)), rhs=(labels(rhs(rules_t))), quality(rules_t))

    ui<- basicPage(
      mainPanel(
        tabsetPanel(
          tabPanel("File", DT::dataTableOutput("df_transac")),
          tabPanel("Rules", DT::dataTableOutput("rules")),
          tabPanel("Graph", plotOutput("graph"))
        )
      )
    )

    server <- function(input, output) {
      output$df_transac = DT::renderDataTable({
        df_transac
      })
      output$rules = DT:: renderDataTable({
        rules_table
      })
      output$graph = renderPlot({
        plot(rules_t,method="scatter",interactive=T)
      })
    }
    shinyApp(ui=ui,server=server)

The app works great when I have

    plot(rules_t,method='scatter",interactive=F)

However, when I have

    plot(rules_t,method='scatter",interactive=T)

I have the following error:

    Error in convertUnit: 'x' argument must be a unit object

Any solution, idea, or reference to previous work is very welcome :)

1

There are 1 best solutions below

2
On BEST ANSWER

The error occurs because it seems that shiny does not pass click locations on to the function grid.locator from package grid. Install the latest arulesViz version and use

plot(rules_t, method = "scatter", engine = "htmlwidget")

instead. This will create a htmlwidget and should work fine in shiny.