绘制第二个反应Apriori不起作用

时间:2016-05-13 23:07:04

标签: r shiny

我有R闪亮的代码:

library(shiny)
ui <- fluidPage(
  titlePanel("Asociačné pravidlá pre odporúčanie"),
  navlistPanel(
    tabPanel("Úvod", textOutput("text1")),
    tabPanel("Experiment 1",sidebarPanel(numericInput("supp", "Vložte hodnotu support", 0.0005, min = 0.0001, max = 0.8, step = 0.0001),
                                         sliderInput("conf","Vložte hodnotu confidence",0.01, min = 0.01, max = 0.8, step = 0.01)),
             #numericInput("conf", "Vložte hodnotu confidence", 0.01, min = 0.01, max = 0.8, step = 0.01)),
             tabsetPanel(tabPanel("Generovanie pravidiel", verbatimTextOutput("rules")),
                         tabPanel("Scatter plot", plotOutput("scatterPlot")),
                         tabPanel("Matrix plot", plotOutput("matrixPlot")),
                         tabPanel("Bodový graf", plotOutput("graphPlot")))),
    tabPanel("Experiment 2",sidebarPanel(numericInput("supp2", "Vložte hodnotu support", 0.025, min = 0.0001, max = 0.8, step = 0.0001),
                                         sliderInput("conf2","Vložte hodnotu confidence",0.01, min = 0.01, max = 0.8, step = 0.01)),
             tabsetPanel(tabPanel("Generovanie pravidiel", verbatimTextOutput("rules2")),
                         tabPanel("Scatter plot", plotOutput("scatterPlot2")),
                         tabPanel("Matrix plot", plotOutput("matrixPlot2")),
                         tabPanel("Bodový graf", plotOutput("graphPlot2")))),

    mainPanel()

  ))

server <- function(input, output){

      library(arulesViz)

rules.all <- reactive({
        apriori(d, parameter=list(support=input$supp, confidence=input$conf, minlen=2, maxlen=3))
      })

  rules.all2 <- reactive({
    apriori(d_, parameter=list(support=input$supp2, confidence=input$conf2, minlen=2, maxlen=3))
  })

  # rules <- reactive({inspect(rules.all)
  #   quality(rules.all) <- round(quality(rules.all), digits=3)
  #                   })

  # rules2 <- reactive({inspect(rules.all2)
  #   quality(rules.all2) <- round(quality(rules.all2), digits=3)
  # })


  output$scatterPlot = renderPlot(
    plot(rules.pruned, method = 'scatterplot')
  )
  output$matrixPlot = renderPlot(
    plot(rules.pruned, method="matrix", measure=c("lift", "confidence"))
  )
  output$graphPlot = renderPlot(
    plot(rules.pruned, method="graph")
  )
  output$scatterPlot2 = renderPlot(
    plot(rules.pruned, method = 'scatterplot')
  )
  output$matrixPlot2 = renderPlot(
    plot(rules.pruned, method="matrix", measure=c("lift", "confidence"))
  )
  output$graphPlot2 = renderPlot(
    plot(rules.pruned, method="graph")
  )
  output$text1 = renderText("Táto jednoduchá aplikácia slúži na rýchlejšiu prácu s algoritmom Apriori. Pre každý experiment generuje algoritmus Apriori asociačné pravidlá z iného vhodného dátového súboru.")

  output$rules    <- renderPrint({rules.all() 
    rules.sorted = sort(rules.all(), by="lift")
    subset.matrix = is.subset(rules.sorted, rules.sorted)
    subset.matrix[lower.tri(subset.matrix, diag=T)] = NA
    redundant = colSums(subset.matrix, na.rm=T) >= 1
    rules.pruned = rules.sorted[!redundant]
    inspect(rules.pruned)
  })
  output$rules2   <- renderPrint({rules.all2() 
    rules.sorted = sort(rules.all(), by="lift")
    subset.matrix = is.subset(rules.sorted, rules.sorted)
    subset.matrix[lower.tri(subset.matrix, diag=T)] = NA
    redundant = colSums(subset.matrix, na.rm=T) >= 1
    rules.pruned = rules.sorted[!redundant]
    inspect(rules.pruned)
  })      
}

shinyApp(ui = ui, server = server)

我有两个反应Apriori:首先是面板'实验1',称为'规则'和'rules.all()',第二个是面板'实验2',称为'rules2'和'rules.all2() ”。

面板'实验1'的Apriori和该面板的3个图表(散点图,矩阵图,bodovýgraf)正在运行,并且面板'实验2'的运行正常。

但是,当我点击面板“实验2”的散点图时,R会在面板“实验1”中给出关于apriori数据的屏幕散点图。

问题出在哪里? 为什么R在两个面板中绘制相同的图形?

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

您无法在sidebarPanel内放置单个tabPanel(请参阅here)。相反,您可以拥有一个sidebarPanel,其中您拥有以激活的tabPanel为条件的内容。