dimanche 1 avril 2018

R shiny error. Unable to get output

I have created the following dataframe and am accessing the same via Shiny

      DF <-
            variable estimatesum
1              Q1    10
2              Q2    3
3              Q3    1
4              Q4    2

I have an input called TotalBase which goes into the second text input as a number.

My Shiny Code is as follows

     ui<- fluidPage(
     textInput("message", label = "message",placeholder = 
          "'"),actionButton("do", "Click Me"),
     textInput("size", label = "size", placeholder = ':')
     ,dateInput("Date",label = "Date"),
     mainPanel(plotOutput("Plot1"),verbatimTextOutput("Output1")))




   server <- function(input, output) {
     output$Plot1 <- renderPlot({
     set.seed(1234)
      wordcloud(words = DF$variable, freq = DF$estimatesum, min.freq = 1,
          max.words=200, random.order=FALSE, rot.per=0.35, 
          colors=brewer.pal(8, "Dark2"))   })

          # The wordcloud works

       text2 <- reactive({
               csize<-input$size
               csize<-as.numeric(csize)
              if(csize<=quantile(TotalBase,0.25)) 
              {Out2=DF[DF$variable=="Q1",]}
              else if((csize>quantile(TotalBase,0.25)) & 
             (csize<=quantile(TotalBase,0.5)))
              {Out2==DF[DF$variable=="Q2",]}
             else if((csize>quantile(TotalBase,0.5)) & 
             (csize<=quantile(TotalBase,0.75)))
             {Out2=DF[DF$variable=="Q3",]}
             else{(Out2=DF[DF$variable=="Q4",])}

              outputtable<-Out2


            })

         output$Output1 <- renderPrint({sum(text2()$estimatesum)})
          }

The code is getting read and the input is Going. I am unable to solve the problem in the if loop. I am getting this message in the loop. I request some some guidance here. Am not comfy with loops in R

   I have added the code for the dataframe here

   DF<-data.frame("variable"<-c("Q1", "Q2", "Q3", "Q4"),
       "estimatesum"<-c(10,3,1,2))
     names(DF)<-c("variable", "estimatesum")

Aucun commentaire:

Enregistrer un commentaire