Cheers everyone, i'm having a little problem in my shiny app but i hope it is something very simple, i just don't know what detail i'm missing.
Basically, my app is based on ShinyPsych package. After the user give the answers of the questions in the "demographic" page, he goes to the results page, and in that part i want to start to do some calculations.
So, my issue is the following:
I have 27 values in the "input" object, that have been given by the user, named "Cards_qu1", "Cards_qu2", ..., "Cards_qu27". Cards refers to the page where the survey is conducted.
Each one of these values carry the index of the choosen product in relation to the data.frame of the design, that is:
Question 1 shows 2 products, which corresponds to the lines 1 and 2 of the design data.frame. If i choose the first product, the value of "Cards_qu1" will be 1.
Questions 3 also shows 2 products, corresponding to the lines 5 and 6 of the design data.frame. If i choose the second product, the value will be 6.
And so on.
I have a data.frame loaded in the app, which is the design for that experiment.
I need to create the vector of choices, to model it in function of the attributes of the design.
My ideia was to, first create a "ZERO" vector, filled with 0's, and then modify the positions in the ZERO vector according to the "positions" of the choosen products of the design.
In base R, this works very well:
x <- rep(0,54) x[sample(1:54,size=27,replace=FALSE)] <- 1
Now, inside the server function in the app, i wrote this. Regarding that "desenho" is the design data.frame already loaded.
choices <- rep(0,54) choices[c(input$Cards_qu1,input$Cards_qu2,input$Cards_qu3,input$Cards_qu4,input$Cards_qu5, input$Cards_qu6,input$Cards_qu7,input$Cards_qu8,input$Cards_qu9,input$Cards_qu10, input$Cards_qu11,input$Cards_qu12,input$Cards_qu13,input$Cards_qu14,input$Cards_qu15, input$Cards_qu16,input$Cards_qu17,input$Cards_qu18,input$Cards_qu19,input$Cards_qu20, input$Cards_qu21,input$Cards_qu22,input$Cards_qu23,input$Cards_qu24,input$Cards_qu25, input$Cards_qu26,input$Cards_qu27)] <- 1 desenho$choices <- choices
I receive an error saying that i'm trying to assign 81 values in a data.frame that contains 54 rows. Somehow inside the app he is concatenating the ZERO vector and the positions values.
I tried to see if the "input$Cards_quX" are saving something else instead of a single numeric value corresponding to the position, but is not.
Someone already faced a issue liek that?
Thank you very much.