我的代码根本不工作,上传文件后没有错误。 ui.r
library(shiny)
shinyUI(fluidPage(
titlePanel("APRIORI"),
sidebarLayout(
sidebarPanel(
h2("Davin", align = "center", style = "color:blue"),
fileInput('gg', 'Choose CSV File', accept=c('.csv')),
plotOutput("imagegro")
),
mainPanel(
dataTableOutput("apriori"),
plotOutput("tops")
)
)
))
服务器server.r
library(shiny)
shinyServer(function(input, output) {
library(arules)
output$tops <- renderPrint({
dong <- input$gg
if (is.null(dong)) return(NULL)
# grocer <- read.csv(CSSSV$datapath)
groceries <- read.transactions(dong$datapath, sep = ",")
# groceries <- read.transactions("jual.csv", sep = ",")
# default settings result in zero rules learned
apriori(groceries)
# set better support and confidence levels to learn more rules
groceryrules <- apriori(groceries, parameter = list(support =
0.2, confidence = 0.76))
# writing the rules to a CSV file
write(groceryrules, file = "groceryrules.csv",
sep = ",", quote = TRUE, row.names = FALSE)
# converting the rule set to a data frame
groceryrules_df <- as(groceryrules, "data.frame")
output$imagegro <- renderPlot(image(groceries))
topconfidence <- sort(groceryrules, decreasing = TRUE, na.last = NA, by = "confidence")
topconfidence_df <- as(topconfidence, "data.frame")
output$apriori <- renderDataTable(topconfidence_df)
})
})
是闪亮的上传不支持read.transactions?
有人可以告诉上传后使用read.transactions的代码...
我的档案jual.csv
broccoli,corn,green pepper
asparagus,corn,squash
bean,corn,squash,tomato
bean,corn,green pepper,tomato
asparagus,bean,broccoli
asparagus,bean,squash,tomato
corn,tomato
broccoli,green pepper,tomato
asparagus,bean,squash
bean,corn
bean,broccoli,green pepper,squash
asparagus,bean,squash
asparagus,bean,corn,squash
bean,broccoli,corn,green pepper,tomato
请帮助......
答案 0 :(得分:1)
我认为你需要研究Shiny是如何工作的。它是一种被动编程语言,与传统编程非常不同。您基本上必须设置一组相互依赖的节点,并在需要时相互更新。一个好的开始是Joe Cheng(Shiny的作者)演讲 - 这里是一个介绍Intro to Shiny,但他也有一些更新的更高级的。
无论如何,这可能就是你要找的东西:
library(shiny)
library(arules)
u <- shinyUI(fluidPage(
titlePanel("APRIORI"),
sidebarLayout(
sidebarPanel(
h2("Davin", align = "center", style = "color:blue"),
fileInput('gg', 'Choose CSV File', accept=c('.csv')),
plotOutput("imagegro")
),
mainPanel(
dataTableOutput("apriori"),
verbatimTextOutput("aprioritxt")
)
)))
s <- shinyServer(function(input, output) {
groceries <- reactive({
req(input$gg)
read.transactions(input$gg$datapath, sep = ",")
})
groceryrules <- reactive({
grules <- apriori(groceries(), parameter = list(support = 0.2, confidence = 0.76))
write(grules, file = "groceryrules.csv", sep = ",", quote=TRUE, row.names=FALSE)
grules
})
groceryrules_df <- reactive({
as(groceryrules(), "data.frame")
})
topconfidence_df <- reactive({
topconfidence <- sort(groceryrules(), decreasing=TRUE, na.last=NA, by="confidence")
topconfidence_df <- as(topconfidence, "data.frame")
})
output$aprioritxt <- renderPrint({ print(apriori(groceries())) })
output$imagegro <- renderPlot({image(groceries())})
output$apriori <- renderDataTable({topconfidence_df()})
})
# options(shiny.reactlog = TRUE) # see visualizer notes below
shinyApp(u,s)
看起来像这样:
可视化节点可能会有所帮助 - 这就是Shiny反应式日志可视化工具,它可以显示日志回放结束时显示的节点:
有关使用此工具的说明,请访问:Reactive Log Visualizer
关于此工具的说明:
options(shiny.reactlog = TRUE)
调用shinyApp