none
r flexdashboards issue with arules reactive input RRS feed

  • Question

  • I'm trying to create a flexdashboard with results from the r aurles aproiri function, so to display associated relations for specific items selected from the pull down menu in the markdown dashboard. When I create function outside the markdown environment I'm able successfully feed the new product item to the aproiri function without problem and the graph changes as expected when I change item. When I replace the function variable with the reactive function name I get an error message saying no rules "Error: x contains 0 rules!"    

    Using the provided Grocery data, I'm want to the reactive input to feed the selected variable either "whole milk" or "sugar" and output the rules for the the specified variable and create a graph.   I'm new to dashboards so I don't know if need to use a different function than the "reactive".

    Below is the markdown code I'm having trouble feeding a new variables into the aproiri function. 

    ---
    title: "Grocery_Test"
    output:
         flexdashboard::flex_dashboard:
          storyboard: true
          social: menu
          source_code: embed
          runtime: shiny
      ---

    ```{r global, include=FALSE}

    library(plotly)
    library(flexdashboard)
    library(htmlwidgets)
    library(htmltools)
    library(knitr)
    library(arules)
    library(arulesViz)
    library(igraph)
    library(datasets)

    data(Groceries)
      
    ```Inputs {.sidebar}
    -----------------------------------------------------------------------

    ```{r}

    selectInput("Product","Product", c("whole milk","sugar"))
    ```

    ###Associated Product
    ```{r}

    product <- reactive({input$product})

    renderPlot({
    #product<-"whole milk"

         rules <- apriori (data=Groceries, parameter=list (supp=0.001,conf = 0.15,maxlen=3)
                                 ,appearance = list(default="rhs",lhs=Product())
                                  ,control = list (verbose=F))

          rules_conf <- sort (rules, by=c("confidence"), decreasing=TRUE) # 'high-confidence' rules.

         redundant <- which (colSums (is.subset (rules_conf, rules_conf)) > 1) # get redundant rules in vector
         rules_conf <- rules_conf[-redundant] # remove redundant rules

          plot(rules_conf, method="graph",measure = "confidence", shading = "lift"
                  ,control = list(engine="htmlwidget"))

      })

    ```

    • Edited by candersn123 Monday, July 2, 2018 3:44 PM Found Misspelling in Code
    Thursday, June 28, 2018 9:31 PM