Skip to content

Instantly share code, notes, and snippets.

@jcheng5
Last active January 31, 2021 13:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jcheng5/6501605 to your computer and use it in GitHub Desktop.
Save jcheng5/6501605 to your computer and use it in GitHub Desktop.
item1,item2,item3,item4,item5,item6,item7,item8,item9,item10
1,1,,,1,1,,,,
,,1,1,,,1,1,,
1,,,,1,,,,1,1
,1,,1,1,,1,,1,
1,1,1,1,1,1,,,,1
,1,,,,,1,,,
,,1,1,1,1,,1,,
1,,,1,,,,1,,1
,,1,1,1,,,,1,1
library(arules)
shinyServer(function(input, output, session) {
rules <- reactive({
if (is.null(input$file))
return(NULL)
dataset <- read.csv(input$file$datapath)
#changing data type to factor
for(i in 1:10){
dataset[,i]<-factor(dataset[,i])
}
#generating rules
rules<-apriori(dataset,parameter=list(support=0.20,confidence=0.20,minlen=2))
return(sort(rules))
})
output$rules <- renderPrint({
# This is a little bit of a hack to prevent the output of calculating the
# rules from being displayed in the "rules" verbatimTextOutput output.
capture.output(rules())
if (is.null(rules()))
return(invisible())
inspect(rules())
})
})
shinyUI(pageWithSidebar(
headerPanel("Association Rules"),
sidebarPanel(
fileInput("file", "File")
),
mainPanel(
verbatimTextOutput("rules")
)
))
@aousabdo
Copy link

aousabdo commented Aug 7, 2015

This helps a lot. Thank you.

@eizoflexscan
Copy link

Thanks... Exactly what I was looking for...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment