Shiny read.transactions 上传后不显示输出

Shiny read.transactions not showing output after upload

我的代码根本不起作用,上传我的文件后没有错误。 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)
  })

})

Running in Web

Rstudio, no error. no respond

闪亮上传不支持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

求助...

我认为您需要研究 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

关于此工具的说明:

  • 通过在 shinyApp 调用
  • 之前插入行 options(shiny.reactlog = TRUE) 启用
  • 它会导致记录节点如何相互激活的日志。
  • 然后可以使用 Ctrl-F3(或 Command-F3)启用日志可视化工具
  • 然后您可以使用箭头键在日志中向后移动(基本上您是在日志中及时移动)。
  • 这里解释反应式符号:Shiny Reactivity Overview
  • 它暴露了很多用户不可见的响应式 activity,因此可能会造成混淆。
  • 它在大型 Shiny 应用程序上运行不佳 - 此工具的许多方面根本无法扩展。