R Flexdashboard问题与规则无功输入

时间:2018-06-30 09:58:07

标签: shinydashboard arules

我正在尝试使用规则apriori函数的结果创建一个flexdashboard,以便显示从markdown仪表板的下拉菜单中选择的特定项目的关联关系。当我在降价环境之外创建函数时,我可以成功地将新产品项馈入apriori函数,而不会出现问题,并且在更改项时图形也会按预期进行更改。当我用反应性函数名称替换函数变量时,出现一条错误消息,提示没有规则“错误:x包含0条规则!”

使用提供的食品杂货数据,我想在反应式输入中输入选定的变量“全脂牛奶”或“糖”,并输出指定变量的规则并创建图表。我是仪表板新手,所以我不知道是否需要使用与“反应式”不同的功能。 下面是markdown代码,我在将新变量输入aproiri函数时遇到了麻烦。

---
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"))

  })

```

0 个答案:

没有答案