** SOLVED **
Hey thanks for clicking! I'm a little late to the shiny party but whatever. My code runs perfectly on shiny, but not after I deploy it onto shinyapps.io. I reckon it has something to do with arules or arulesViz. The datatable just doesn't load after I click the button.
** VIEW EDIT BELOW **
Consequential code here-
UI Side
tabPanel("Market Basket Analysis",
sidebarLayout(
sidebarPanel(
h4("Item Association Analysis"),
actionButton("mark","Plot Most Common Items"),
actionButton("bask","Association Rules")
),
mainPanel(
h3("Most Common Items"),
plotOutput("plot9"),
h3("Association Rules"),
dataTableOutput("table10")
)
)
)
Server Side
output$plot9<-renderPlot({req(input$mark)
input$mark
library(arules)
library(arulesViz)
ceditems<-ced$items
ceditems$Sales.Register.Num<-as.numeric(ceditems$Sales.Register.Num)
ceditems<-ceditems %>% mutate(CatalogNo=as.factor(CatalogNo))
trans<-split(ceditems$CatalogNo,ceditems$Sales.Register.Num)
tr<-as(trans,"transactions")
ced$tr<-tr
library(RColorBrewer)
itemFrequencyPlot(tr,topN=20,type="absolute",col=brewer.pal(8,'Pastel2'), main="Absolute Item Frequency Plot")
})
output$table10<-renderDataTable({req(input$bask)
input$bask
tr<-ced$tr
association.rules <- apriori(tr, parameter = list(supp=0.001, conf=0.8,maxlen=10))
subset.rules <- which(colSums(is.subset(association.rules, association.rules)) > 1)
association.rules <- association.rules[-subset.rules]
best<-as.data.frame(inspect(association.rules[1:length(association.rules)]))
})
The ItemFrequencyPlot renders fine, but then I click Association Rules and nothing happens. In the shinyapps log, I get no errors, in fact, I actually get the output I want there. Locally, it prints twice- once to console and once to the renderDataTable. Online, it just prints to the log console. I'm worried it has to do with the size of the split() file, but I get no errors that would make me believe so. Hope someone can help!
Thanks!
EDIT: I'm getting the feeling that the problem lies in the inspect() function. How can you view the association rules without inspect()? Thanks
SOLVED: Yes the inspect() function was the problem. I'm not sure why everyone suggests you use that terrible function that doesn't return anything. Arules has a function arules::DATAFRAME(association.rules,separate=TRUE) that works much better.