Reputation: 2877
I am trying to build a data mining app which allows the user to specify via drop downs what the support and confidence should be as well as the option to order by these by support, confidence and lift.
I wish to allow the user to specify the antecedent and the consequent via separate free text boxes.
This type of sub-setting is performed after the rules have been generated:
library("arules")
data("Adult")
## Mine rules
rules <- apriori(Adult, parameter = list(support = 0.3))
subset(rules, subset = rhs %pin% "marital-status=")
My though process was that if the text field was empty then return all rules from the apriori algorithm else if the text field was not empty then use the text to subset the rules. I have tried implementing this using an if_else but I am getting the following error:
object of type 'S4' is not subsettable
My code looks as follows:
library(shiny)
# Define UI for application that computes association rules
ui <- fluidPage(
# Application title
titlePanel("Association Rules"),
# Sidebar with drop down options for confidence, support and lift
sidebarLayout(
sidebarPanel(
selectInput("sup", "Select the support value", choices = supportLevels),
selectInput("conf", "Select the confidence", choices = confidenceLevels),
selectInput("order", "Sorting Criteria", choices = c("support", "confidence", "lift")),
width = 2,
textInput("antecedent", "Enter an antecedent", placeholder = "e.g. HUMALOG")
),
mainPanel(
verbatimTextOutput("mba"),
width = 10
)
)
)
# Define server logic to mine frequent rules
server <- function(input, output) {
output$mba <- renderPrint({
rules <- apriori(transactions,
parameter = list(support = as.numeric(input$sup),
confidence = as.numeric(input$conf),
minlen = 2,
target = "rules"))
inspect(sort(if_else(is.null(input$antecedent),rules,subset(rules,subset = lhs %pin% input$antecedent)), by = input$order))
})
}
# Run the application
shinyApp(ui = ui, server = server)
Can anyone help me with how I can subset my rules in Shiny so that the user can filter down to a product of interest?
Upvotes: 0
Views: 165