0

I have these code of R shiny:

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)

I have two reactive Apriori: first for the panel 'Experiment 1' called 'rules' and 'rules.all()', and second for the panel 'Experiment 2' called 'rules2' and 'rules.all2()'.

Apriori for the panel 'Experiment 1' and 3 graphs for this panel (scatter plot,matrix plot,bodový graf) are running right and apriori for the panel 'Experiment 2' is running right.

But when I clicked on the scatter plot for the panel 'Experiment 2', R gives me on the screen scatter plot for the data from apriori in the panel 'Experiment 1'.

Where is the problem ? Why R plotting the same graph in both panels ?

Thanks for help.

Charles Mager
  • 25,735
  • 2
  • 35
  • 45

1 Answers1

0

You can't place individual sidebarPanels inside the tabPanels (see here). Instead, you can have one sidebarPanel where you have stuff conditional on the tabPanel that is activated.

Community
  • 1
  • 1
tchakravarty
  • 10,736
  • 12
  • 72
  • 116
  • Hi, thanks for you help but I don't know run my second apriori with data from your link. Can you give me good example with this instructions on my code please ? – Dávid Kron May 16 '16 at 17:22