lundi 5 décembre 2016

R Shiny: checkboxGroupInput reactivating plot

i'm unfamiliar with Shiny but i would like to make my checkboxGroupInput change output plot. The plot shows part of two statistics (Y1 + Y2) in Total. Firstly, i've made a plot without seperate Generations using.

plot(selectedData2()+selectedData3() ~Total,  type="p",  main="Title",ylab="Y1_var + Y2_var",col=c(1,2,3),cex=1.5)

Now, i would like to determine which Generation will show up (i wish they could sum up so i could show 1st + 2nd + 3rd generations or 1st+6th generations).

Here is fragment of ui.R

sidebarPanel(
    selectInput('yy1', 'Y1 Variable', names(data[,c(6:11)])),
    selectInput('yy2', 'Y2 Variable', names(data[,c(6:11)]),
                selected = names(data)[7]),
    selectInput('idName', 'Pokemon', unique(data$Name)),
    radioButtons("legend", label = h4("Is Legendary?"),
    choices = list("Yes" = 1, "No" = 2), 
              selected = 1),
    checkboxGroupInput("Generacja", label = h3("Generation"), 
    choices = c("1st" = 1, "2nd" = 2, "3rd" = 3,"4th" = 4,"5th" = 5,"6th" = 6),
              selected = 1)
),
mainPanel(
          plotOutput('unif')
),
h4("Stats"),
verbatimTextOutput("stats")
),

Here is fragment of server.R

selectedData2 <- reactive({
data[,input$yy1 ]
})

selectedData3 <- reactive({
data[,input$yy2 ]
})


 output$unif <- renderPlot({
 par(mar = c(5.1, 4.1, 2, 1))
plot(selectedData2()+selectedData3() ~Total,  type="p",  main="Title",ylab="Y1_var + Y2_var",col=c(1,2,3),cex=1.5)

#Here is only for Generation == 1  

#plot(selectedData2()[Generation=="1"]+selectedData3()[Generation=="1"] ~Total[Generation=="1"],  type="p",  main="Title",ylab="Y1_var + Y2_var",col=c(1,2,3),cex=1.5)

#Here is my fail which i don't know how to repair

#plot(selectedData2()[Generation==input$Generacja]+selectedData3()[Generation==input$Generacja] ~Total[Generation==input$Generacja],  type="p",  main="Title",ylab="Y1_var + Y2_var",col=c(1,2,3),cex=1.5)

  points(selectedData2()[Name==input$idName] +  selectedData3()[Name==input$idName] ~Total[Name==input$idName],pch=3,lwd=2, cex=5)
})


 output$stats <- renderPrint({
 head(data[order(selectedData2()+selectedData3(),decreasing=T),])
 })

Here is what I would like to achieve with your help (now it shows only for Generation == 1) http://ift.tt/2fZUgY2

I thank you and I await a reply.

Aucun commentaire:

Enregistrer un commentaire