"Warning: Error in : object of type 'closure' is not subsettable: error message

Hello,

Beginner R programmer here, still working on a Jeopardy! project where I publish a quiz. I have one published here...

https://taylorjsimpson.shinyapps.io/quizz/?_ga=2.231350367.1787431904.1592511756-926734937.1590084764

I am working on an update where I print out all of the correct answers after a user submits their own answers, but ran into a problem. I keep getting this error message...
"Warning: Error in : object of type 'closure' is not subsettable
100: tagWrite
99: doRenderTags
98: processDeps
97: transform
96: func
94: f
93: Reduce
84: do
83: hybrid_chain
82: origRenderFunc
81: output$number_correct
1: runApp"

I have tried debugging myself and using the internet as a resource, but couldn't find the answer using this...

I don't know what the issue here is. I have the exact same code as I have in my app that is published and works except for what I have at the end where I am attempting to print out the correct answers. Code is below...

ui <- fluidPage(
    
    #creates a set of radio buttons, only one of which can be pressed at any time
    #id: rand_or_spec-what i refer to it as and its stored as computationally, label is radio buttons with h3-hierarchical difference f|| formatting
    #choices: a list of values, widget will build a button f|| each value of the list. text/value LIKE key/value. text shows up, value is whats stored as computationally
    #selected: value that should be initially selected
    radioButtons("rand_or_spec", label = h3("Radio buttons"),
                 choices = list("Random Category" = 1, "Specific Category" = 2), 
                 selected = NULL), 
    #placeholder from when server going to plug in text box
    uiOutput("Specific_Category"),
    #creates action button f|| submitting users choice, either random || what they enter
    actionButton("submit_category", label = "SUBMIT"),
    #area that prints what the category is after they have been selected
    uiOutput("category_selected"),
    #placeholder f|| when server puts in questions into text boxes f|| all 5 questions (cont'd) 
    #and text box f|| user to answer questions
    uiOutput("quiz"),
    #printing # correct
    uiOutput("number_correct")
    
    
    
    
    
)
#creates server function, which is where the output is generated, some of which are puts of the ui. 
#server is listener.input is clicked, output is generated
#render is action button to take stuff from server and render it to ui
#can put server in seperate file in ui
server <- function(input, output){
    #imports jeop3column dataframe from csv
    jeop3column <- read.csv(file = "data/jeop3column2.csv")
    #observes aka if ANY of the inputs referenced that are mentioned in observe function changes, code in the observe runs again: if specific_category is chosen, render Specific_Category
    #creates new textinput button with ID of user_category, without a label, that says "input category here"
    #|| else, BREAK -> go to next section
    observe({
        if(input$rand_or_spec == 2){
            output$Specific_Category <- renderUI({
                #taglist makes output get one html element, computationally known as "user_category", no label, text
                tagList(textInput("user_category", label = NULL, value = "input category here"))
                
            })
        }
        else{
            output$Specific_Category <- renderUI({
                br()
            })
        }
    })
    
    #next observe the event that if/WHEN the submit category button is clicked, then following code will be run
    #create a variable called single category that is a random selection of 
    #a category from my df. 
    #sample is a function f|| a random selection, 1 = sample size, [[1]] == get a string and not list
    observeEvent(input$submit_category, {
        if(input$rand_or_spec == 1){
            
            single_cat<- sample(unique(as.character(jeop3column$category)), 1)
            
            #if not random, single_cat = user input f|| user category   
        } else{
            #if what user entered in cateogry, uses that, DO MORE FUZZY WUZZY
            if (input$user_category %in% jeop3column$category)
                single_cat <- input$user_category
            else
                single_cat<- sample(unique(as.character(jeop3column$category)), 1)[[1]]
        }
        #single_cat_df == subset of jeop3column where category == selected single category
        #single_cat with 5 questions == sample of scdf with 5 selections of rows, all the columns
        
        
        
        #function f|| validating category
        #if number of rows in dataframe where category is category >=5, category is ok
        #|| else new category = a new random sample from df, then repeat >=5
        validate_cat <- function (cat){
            if (nrow(jeop3column[jeop3column$category == cat,]) >= 5){
                return(cat)
            }
            else{
                new_cat <- sample(unique(as.character(jeop3column$category)), 1)
                validate_cat(new_cat)
            }
        }
        
        #single category being selected
        single_cat <- validate_cat(single_cat)
        single_cat_df <- jeop3column[jeop3column$category == single_cat, ]
        single_cat_df_5 <- single_cat_df[sample(nrow(single_cat_df), 5), ]
        
        #observe when category is created and create displayed category button
        
        output$category_selected <- renderUI({
            paste("Category Selected: ", single_cat)
            
        })
        
        #output of quiz
        #what does tag list do
        #creates text input, label is question, then populates 1st q from df, enter text f|| answer 
        #paste joins two strings in r: question 1 AND question from DF  
        
        output$quiz <- renderUI({
            tagList(
                textInput("answer1", label = h3(paste("QUESTION 1: ", single_cat_df_5$answer[1])), value = "Enter text..."),
                textInput("answer2", label = h3(paste("QUESTION 2: ", single_cat_df_5$answer[2])), value = "Enter text..."),
                textInput("answer3", label = h3(paste("QUESTION 3: ", single_cat_df_5$answer[3])), value = "Enter text..."),
                textInput("answer4", label = h3(paste("QUESTION 4: ", single_cat_df_5$answer[4])), value = "Enter text..."),
                textInput("answer5", label = h3(paste("QUESTION 5: ", single_cat_df_5$answer[5])), value = "Enter text..."),
                actionButton("submit_answers", label = "Submit Answers")
            )
        })
    })
    
    #agrep("Nixon", "Nixon")
    
    #s1a = "Nixon"
    #s1b = "naxon"
    
    
    
    observeEvent(input$submit_answers, {
        num_right <- 0
        
        
        
        output$number_correct <- renderUI({
            paste("Percentage correct", "YOU GOT A: ", num_right)
        
        output$correct_answers <- renderUI({
            taglist(
           textInput("answer1", label = h3(paste("ANSWER 1: ", single_cat_df_5$question[1])), value = "Enter text..."),
                    textInput("answer2", label = h3(paste("ANSWER 2: ", single_cat_df_5$question[2])), value = "Enter text..."),
                    textInput("answer3", label = h3(paste("AnSWER 3: ", single_cat_df_5$question[3])), value = "Enter text..."),
                    textInput("answer4", label = h3(paste("ANSWER 4: ", single_cat_df_5$question[4])), value = "Enter text..."),
                    textInput("answer5", label = h3(paste("ANSWER 5: ", single_cat_df_5$question[5])), value = "Enter text..."),
            )
        })
    })
    
    
   
    
    
    }

)}
shinyApp(ui = ui, server = server)

The section I likely need to troubleshoot is below...

output$correct_answers <- renderUI({
            textInput("answer1", label = h3(paste("ANSWER 1: ", single_cat_df_5$question[1])), value = "Enter text..."),
                    textInput("answer2", label = h3(paste("ANSWER 2: ", single_cat_df_5$question[2])), value = "Enter text..."),
                    textInput("answer3", label = h3(paste("AnSWER 3: ", single_cat_df_5$question[3])), value = "Enter text..."),
                    textInput("answer4", label = h3(paste("ANSWER 4: ", single_cat_df_5$question[4])), value = "Enter text..."),
                    textInput("answer5", label = h3(paste("ANSWER 5: ", single_cat_df_5$question[5])), value = "Enter text..."),

The formatting works for above in my code when it populates the questions, but when I Want to show the correct answers it gives me the error message of "Warning: Error in : object of type 'closure' is not subsettable".

Any help or guidance would be appreciated as I'm somewhat stuck here.

Thanks!

-Taylor

This is not a reprex as we dont have your csv.
you should read your csv to an object, and then dput() that object (or a portion of it) to share on the forum for a reprex.

That said, nested renderUI calls... they make me very uncomfortable, I can't think of a good reason to do that. and it may be part of your issue. Besides which there is no corresponding UI called 'correct_answers' for the output$correct_answers to be the server definition for, so I wouldn't expect to see any result.

   if (input$answer1 == single_cat_gen$question[1])
            num_right <- num_right + 1
#> Error in eval(expr, envir, enclos): object 'input' not found
        if (input$answer2 == single_cat_gen$question[2])
            num_right <- num_right + 1
#> Error in eval(expr, envir, enclos): object 'input' not found
        if (input$answer3 == single_cat_gen$question[3])
            num_right <- num_right + 1
#> Error in eval(expr, envir, enclos): object 'input' not found
        if (input$answer4 == single_cat_gen$question[4])
            num_right <- num_right + 1
#> Error in eval(expr, envir, enclos): object 'input' not found
        if (input$answer5 == single_cat_gen$question[5])
            num_right <- num_right + 1
#> Error in eval(expr, envir, enclos): object 'input' not found

Created on 2020-06-25 by the reprex package (v0.3.0)
.

Hopefully the reprex above worked! I managed to get all the correct answers printed out! I added the corresponding ui up top stayed away from the nested renderUI calls and used similar formatting that I used for the number correct message. Thing is I still have a problem...

I now have an error message and am unable to now get the number of correct answers printed. Error message is at the top via reprex and below in the console as follows...

Warning: Error in : object of type 'closure' is not subsettable
  100: tagWrite
   99: doRenderTags
   98: processDeps
   97: transform
   96: func
   94: f
   93: Reduce
   84: do
   83: hybrid_chain
   82: origRenderFunc
   81: output$number_correct
    1: runApp

I tried doing using dput() on my csv so I could share on the forum, but was unable to get it working. Hopefully the reprex above is enough to help me troubleshoot.

So I googled the error message and it says it likely means that i have a variable that represents a function, and mistakenly using square brackets to try and subset it thinking it represents a dataframe or vector or something.

After some more troubleshooting I'm almost positive it has to do with where I am referencing where the submitted answers are matched with the user inputted answers. Somehow it is not reading either the input$submitanswers, and/or any of the input$answer1-5.

The strange thing is that I have the EXACT same code to match user input with dataframe answers in my working app, so am somewhat unclear of what the issue is.

Any idea of why this script isn't reading the user inputted answers like my working script is? Or what I could do to find out?

I never reprexed before but if the full code isn't shown I can post the non-working and working section of code in a follow up message.

Thanks!

-Taylor

CODE THAT WORKS, SEE AFTER "observeEvent(input$submit_answers, {" near bottom

#reprex::reprex()
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
#    http://shiny.rstudio.com/
#
#output server generates, input user interacts with. server output CAN BE more places for user input
#loads in shiny library

library(shiny)
#library(fuzzywuzzyR)

#sets user interface, which is what user sees/interacts with, type of UI
ui <- fluidPage(
    
    #creates a set of radio buttons, only one of which can be pressed at any time
    #id: rand_or_spec-what i refer to it as and its stored as computationally, label is radio buttons with h3-hierarchical difference for formatting
    #choices: a list of values, widget will build a button for each value of the list. text/value LIKE key/value. text shows up, value is whats stored as computationally
    #selected: value that should be initially selected
    radioButtons("rand_or_spec", label = h3("Radio buttons"),
                 choices = list("Random Category" = 1, "Specific Category" = 2), 
                 selected = NULL), 
    #placeholder from when server going to plug in text box
    uiOutput("Specific_Category"),
    #creates action button for submitting users choice, either random or what they enter
    actionButton("submit_category", label = "SUBMIT"),
    #area that prints what the category is after they have been selected
    uiOutput("category_selected"),
    #placeholder for when server puts in questions into text boxes for all 5 questions (cont'd) 
    #and text box for user to answer questions
    uiOutput("quiz"),
    #printing # correct
    uiOutput("number_correct")
    
    
    
    
    
)
#creates server function, which is where the output is generated, some of which are puts of the ui. 
#server is listener.input is clicked, output is generated
#render is action button to take stuff from server and render it to ui
#can put server in seperate file in ui
server <- function(input, output){
    validate_cat <- function (cat){
        if (nrow(jeop3column[jeop3column$category == cat,]) >= 5){
            return(cat)
        }
        else{
            new_cat <- sample(unique(as.character(jeop3column$category)), 1)
            validate_cat(new_cat)
        }
    }
    #imports jeop3column dataframe from csv
    jeop3column <- read.csv(file = "data/jeop3column2.csv")
    #observes aka if ANY of the inputs referenced that are mentioned in observe function changes, code in the observe runs again: if specific_category is chosen, render Specific_Category
    #creates new textinput button with ID of user_category, without a label, that says "input category here"
    #or else, BREAK -> go to next section
    observe({
        if(input$rand_or_spec == 2){
            output$Specific_Category <- renderUI({
                #taglist makes output get one html element, computationally known as "user_category", no label, text
                tagList(textInput("user_category", label = NULL, value = "input category here"))
                
            })
        }
        else{
            output$Specific_Category <- renderUI({
                br()
            })
        }
    })
    
    #next observe the event that if/WHEN the submit category button is clicked, then following code will be run
    #create a variable called single category that is a random selection of 
    #a category from my df. 
    #sample is a function for a random selection, 1 = sample size, [[1]] == get a string and not list
    single_cat_gen <- 'b0o'
    observeEvent(input$submit_category, {
        if(input$rand_or_spec == 1){
            
            single_cat <- sample(unique(as.character(jeop3column$category)), 1)
            
            #if not random, single_cat = user input for user category   
        } else{
            #if what user entered in cateogry, uses that, DO MORE FUZZY WUZZY
            if (input$user_category %in% jeop3column$category)
                single_cat <- input$user_category
            else
                single_cat <- sample(unique(as.character(jeop3column$category)), 1)[[1]]
        }
        #single_cat_df == subset of jeop3column where category == selected single category
        #single_cat with 5 questions == sample of scdf with 5 selections of rows, all the columns
        
        
        
        #function for validating category
        #if number of rows in dataframe where category is category >=5, category is ok
        #or else new category = a new random sample from df, then repeat >=5
        validate_cat <- function (cat){
            if (nrow(jeop3column[jeop3column$category == cat,]) >= 5){
                print(cat)
                return(cat)
            }
            else{
                new_cat <- sample(unique(as.character(jeop3column$category)), 1)
                validate_cat(new_cat)
            }
        }
        
        #single category being selected
        single_cat <- validate_cat(single_cat)
        single_cat_df <- jeop3column[jeop3column$category == single_cat, ]
        single_cat_df_5 <- single_cat_df[sample(nrow(single_cat_df), 5), ]
        single_cat_gen <<- single_cat_df_5
        #observe when category is created and create displayed category button
        
        output$category_selected <- renderUI({
            paste("Category Selected: ", single_cat)
            
        })
        
        #output of quiz
        #what does tag list do
        #creates text input, label is question, then populates 1st q from df, enter text for answer 
        #paste joins two strings in r: question 1 AND question from DF  
        
        output$quiz <- renderUI({
            tagList(
                textInput("answer1", label = h3(paste("QUESTION 1: ", single_cat_gen$answer[1])), value = "Enter text..."),
                textInput("answer2", label = h3(paste("QUESTION 2: ", single_cat_gen$answer[2])), value = "Enter text..."),
                textInput("answer3", label = h3(paste("QUESTION 3: ", single_cat_gen$answer[3])), value = "Enter text..."),
                textInput("answer4", label = h3(paste("QUESTION 4: ", single_cat_gen$answer[4])), value = "Enter text..."),
                textInput("answer5", label = h3(paste("QUESTION 5: ", single_cat_gen$answer[5])), value = "Enter text..."),
                actionButton("submit_answers", label = "Submit Answers")
            )
        })
    })
    
    
    
    
    observeEvent(input$submit_answers, {
        num_right <- 0
        
       
        
        
        if (input$answer1 == single_cat_gen$question[1])
            num_right <- num_right + 1
        if (input$answer2 == single_cat_gen$question[2])
            num_right <- num_right + 1
        if (input$answer3 == single_cat_gen$question[3])
            num_right <- num_right + 1
        if (input$answer4 == single_cat_gen$question[4])
            num_right <- num_right + 1
        if (input$answer5 == single_cat_gen$question[5])
            num_right <- num_right + 1
        
        output$number_correct <- renderUI({
            paste("Percentage correct", "YOU GOT A: ", num_right)
        })
    })
    
    
    
    
    
    
}



shinyApp(ui = ui, server = server)

CODE THAT DOESN'T WORK, SEE AFTER "observeEvent(input$submit_answers, {" NEAR BOTTOM. WHY DOES THIS NOT WORK WHEN OTHER DOES?

#reprex::reprex()
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
#    http://shiny.rstudio.com/
#

#output server generates, input user interacts with. server output CAN BE more places f|| user input
#loads in shiny library

library(shiny)
library(fuzzywuzzyR)

#sets user interface, which is what user sees/interacts with, type of UI
ui <- fluidPage(
    
    #creates a set of radio buttons, only one of which can be pressed at any time
    #id: rand_or_spec-what i refer to it as and its stored as computationally, label is radio buttons with h3-hierarchical difference f|| formatting
    #choices: a list of values, widget will build a button f|| each value of the list. text/value LIKE key/value. text shows up, value is whats stored as computationally
    #selected: value that should be initially selected
    radioButtons("rand_or_spec", label = h3("Radio buttons"),
                 choices = list("Random Category" = 1, "Specific Category" = 2), 
                 selected = NULL), 
    #placeholder from when server going to plug in text box
    uiOutput("Specific_Category"),
    #creates action button f|| submitting users choice, either random || what they enter
    actionButton("submit_category", label = "SUBMIT"),
    #area that prints what the category is after they have been selected
    uiOutput("category_selected"),
    #placeholder f|| when server puts in questions into text boxes f|| all 5 questions (cont'd) 
    #and text box f|| user to answer questions
    uiOutput("quiz"),
    #printing # correct
    uiOutput("number_correct"),
    #printing correct answers
    uiOutput("correct_answers")
    
    
    
    
    
)
#creates server function, which is where the output is generated, some of which are inputs of the ui. 
#server is listener.input is clicked, output is generated
#render is action button to take stuff from server and render it to ui
#can put server in seperate file in ui
server <- function(input, output){
    #imports jeop3column dataframe from csv
    jeop3column <- read.csv(file = "data/jeop3column2.csv")
    #dput_small1(jeop3column, stringsAsFactors=TRUE)
    #observes aka if ANY of the inputs referenced that are mentioned in observe function changes, code in the observe runs again: if specific_category is chosen, render Specific_Category
    #creates new textinput button with ID of user_category, without a label, that says "input category here"
    #|| else, BREAK -> go to next section
    observe({
        if(input$rand_or_spec == 2){
            output$Specific_Category <- renderUI({
                #taglist makes output get one html element, computationally known as "user_category", no label, text
                tagList(textInput("user_category", label = NULL, value = "input category here"))
                
            })
        }
        else{
            output$Specific_Category <- renderUI({
                br()
            })
        }
    })
    #creating single_cat_gen variable for SCOPE, because single_cat_gen is created within observevent
    #next observe the event that if/WHEN the submit category button is clicked, then following code will be run
    #create a variable called single category that is a random selection of 
    #a category from my df. 
    #sample is a function f|| a random selection, 1 = sample size, [[1]] == get a string and not list
    
    single_cat_gen <- 'b0o'
    observeEvent(input$submit_category, {
        if(input$rand_or_spec == 1){
            
            single_cat<- sample(unique(as.character(jeop3column$category)), 1)
            
            #if not random, single_cat = user input f|| user category   
        } else{
            #if what user entered in cateogry, uses that, DO MORE FUZZY WUZZY
            if (input$user_category %in% jeop3column$category)
                single_cat <- input$user_category
            else
                single_cat<- sample(unique(as.character(jeop3column$category)), 1)[[1]]
        }
        #single_cat_df == subset of jeop3column where category == selected single category
        #single_cat with 5 questions == sample of scdf with 5 selections of rows, all the columns
        
        
        
        #function f|| validating category
        #if number of rows in dataframe where category is category >=5, category is ok
        #|| else new category = a new random sample from df, then repeat >=5
        validate_cat <- function (cat){
            if (nrow(jeop3column[jeop3column$category == cat,]) >= 5){
                return(cat)
            }
            else{
                new_cat <- sample(unique(as.character(jeop3column$category)), 1)
                validate_cat(new_cat)
            }
        }
        
        #single category being selected
        single_cat <- validate_cat(single_cat)
        single_cat_df <- jeop3column[jeop3column$category == single_cat, ]
        single_cat_df_5 <- single_cat_df[sample(nrow(single_cat_df), 5), ]
        single_cat_gen <<- single_cat_df_5
        #observe when category is created and create displayed category button
        
        output$category_selected <- renderUI({
            paste("Category Selected: ", single_cat)
            
        })
        
        #output of quiz
        #what does tag list do
        #creates text input, label is question, then populates 1st q from df, enter text f|| answer 
        #paste joins two strings in r: question 1 AND question from DF  
        
        output$quiz <- renderUI({
            tagList(
                textInput("answer1", label = h3(paste("QUESTION 1: ", single_cat_df_5$answer[1])), value = "Enter text..."),
                textInput("answer2", label = h3(paste("QUESTION 2: ", single_cat_df_5$answer[2])), value = "Enter text..."),
                textInput("answer3", label = h3(paste("QUESTION 3: ", single_cat_df_5$answer[3])), value = "Enter text..."),
                textInput("answer4", label = h3(paste("QUESTION 4: ", single_cat_df_5$answer[4])), value = "Enter text..."),
                textInput("answer5", label = h3(paste("QUESTION 5: ", single_cat_df_5$answer[5])), value = "Enter text..."),
                actionButton("submit_answers", label = "Submit Answers")
            )
        })
    })
    
   
    single_cat_gen <- 'bOo'
    observeEvent(input$submit_answers, {
        num_right <- 0
        
        if (input$answer1 == single_cat_gen$question[1])
            num_right <- num_right + 1
        if (input$answer2 == single_cat_gen$question[2])
            num_right <- num_right + 1
        if (input$answer3 == single_cat_gen$question[3])
            num_right <- num_right + 1
        if (input$answer4 == single_cat_gen$question[4])
            num_right <- num_right + 1
        if (input$answer5 == single_cat_gen$question[5])
            num_right <- num_right + 1
        
       
        
        output$number_correct <- renderUI({
            paste("Percentage correct", "YOU GOT A: ", num_right)
            
        output$correct_answers <- renderUI({
            paste("Correct Answer", "Question 1: ", single_cat_gen$question[1],
                  "Correct Answer", "Question 2: ", single_cat_gen$question[2],
                  "Correct Answer", "Question 3: ", single_cat_gen$question[3],
                  "Correct Answer", "Question 4: ", single_cat_gen$question[4],
                  "Correct Answer", "Question 5: ", single_cat_gen$question[5])
                 
                
                
            })
        })
        
        
        
        
        
    }
    
    )}
shinyApp(ui = ui, server = server)
    jeop3column <- read.csv(file = "data/jeop3column2.csv")
   dput(jeop3column)

This is my code

reprex::reprex()
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
#    http://shiny.rstudio.com/
#

#output server generates, input user interacts with. server output CAN BE more places f|| user input
#loads in shiny library

library(shiny)
library(fuzzywuzzyR)

#sets user interface, which is what user sees/interacts with, type of UI
ui <- fluidPage(
    
    #creates a set of radio buttons, only one of which can be pressed at any time
    #id: rand_or_spec-what i refer to it as and its stored as computationally, label is radio buttons with h3-hierarchical difference f|| formatting
    #choices: a list of values, widget will build a button f|| each value of the list. text/value LIKE key/value. text shows up, value is whats stored as computationally
    #selected: value that should be initially selected
    radioButtons("rand_or_spec", label = h3("Radio buttons"),
                 choices = list("Random Category" = 1, "Specific Category" = 2), 
                 selected = NULL), 
    #placeholder from when server going to plug in text box
    uiOutput("Specific_Category"),
    #creates action button f|| submitting users choice, either random || what they enter
    actionButton("submit_category", label = "SUBMIT"),
    #area that prints what the category is after they have been selected
    uiOutput("category_selected"),
    #placeholder f|| when server puts in questions into text boxes f|| all 5 questions (cont'd) 
    #and text box f|| user to answer questions
    uiOutput("quiz"),
    #printing # correct
    uiOutput("number_correct"),
    #printing correct answers
    uiOutput("correct_answers")
    
    
    
    
    
)
#creates server function, which is where the output is generated, some of which are inputs of the ui. 
#server is listener.input is clicked, output is generated
#render is action button to take stuff from server and render it to ui
#can put server in seperate file in ui
server <- function(input, output){
    #imports jeop3column dataframe from csv
    jeop3column <- read.csv(file = "data/jeop3column2.csv")
    dput(jeop3column)

And I get this error message

runApp('jeopractice')
Rendering reprex...
Error: callr subprocess failed: :18:5: unexpected symbol
17: #+ reprex-body
18: The Vanishing
^
Type .Last.error.trace to see where the error occured

.Last.error.trace

Stack trace:

Process 16252:

  1. shiny:::runApp("jeopractice")
  2. appParts$onStart()
  3. shiny:::appObj()
  4. shiny:::func(fname, ...)
  5. shiny:::sourceUTF8(fullpath, envir = new.env(parent = sharedEnv))
  6. base:::eval(exprs, envir)
  7. base:::eval(exprs, envir)
  8. shiny:::..stacktraceon..({ ...
  9. reprex::reprex()
  10. reprex:::reprex_render(r_file, std_file)
  11. callr::r_safe(function(input) { ...
  12. callr:::get_result(output = out, options)
  13. throw(newerr, parent = remerr[[2]])

x callr subprocess failed: :18:5: unexpected symbol
17: #+ reprex-body
18: The Vanishing
^

Process 8860:
25. (function (input) ...
26. rmarkdown::render(input, quiet = TRUE, envir = globalenv())
27. knitr::spin(spin_input, knit = FALSE, envir = envir, format = "Rmd")
28. utils:::getParseData(parse(text = x, keep.source = TRUE))
29. base:::parse(text = x, keep.source = TRUE)
30. base:::.handleSimpleError(function (e) ...
31. h(simpleError(msg, call))

x :18:5: unexpected symbol
17: #+ reprex-body
18: The Vanishing
^

Was what I got before when I tried using dput().

I still am trying to figure out why I get the "Error: object of type closure' is not subsettable' error message in my app, and this error message in my console...

Warning: Error in : object of type 'closure' is not subsettable
100: tagWrite
99: doRenderTags
98: processDeps
97: transform
96: func
94: f
93: Reduce
84: do
83: hybrid_chain
82: origRenderFunc
81: output$number_correct
1: runApp

^^^above makes me think it has to do with the "output$number_correct" ^^^

Sorry the dput() doesn't seem to work, if you have any ideas of what I could do so that it would or still be able to solve why the number correct still won't print out please advise.

Thanks again!

-Taylor

dput() is not something that belongs anywhere in your app
dput is a command you type in your console to get a specific response in your console.

FAQ: How to do a minimal reproducible example ( reprex ) for beginners

1 Like

Working on this now! Wanting to understand this, so essentially....

A reprex is a representative example of a coding issue, which essentially is a way to share code I am working on in R on this site.I need to include the data and the code that's causing my trouble.

First I need to use dput() on my dataframe, and then i need to take the minimum reproducible code to share.

I ran dput(head(Jeop3column, 5)[c("category", "question", "answer)]) in my console and that gave me...a bunch of alphabetized data.
In the link the user then included the libraries needed, created a dataframe, and had the problematic part of their code. I would assume I would then need something like this...

library(shiny)

 df <- data.frame(stringsAsFactors = FALSE,
                  category = c(WHAT GOES HERE),
                  question = c(WHAT GOES HERE),
                  answer = c(WHAT GOES HERE)

#PROBLEMATIC PART OF CODE
#printing # correct
    uiOutput("number_correct"),

observeEvent(input$submit_answers, {
        num_right <- 0
        
        if (input$answer1 == single_cat_gen$question[1])
            num_right <- num_right + 1
        if (input$answer2 == single_cat_gen$question[2])
            num_right <- num_right + 1
        if (input$answer3 == single_cat_gen$question[3])
            num_right <- num_right + 1
        if (input$answer4 == single_cat_gen$question[4])
            num_right <- num_right + 1
        if (input$answer5 == single_cat_gen$question[5])
            num_right <- num_right + 1

output$number_correct <- renderUI({
            paste("Percentage correct", "YOU GOT A: ", num_right)

This seems like it is generally the right idea, but I'm not entirely sure, because the questions I have are...
-in the example from the link is someone creating a dataframe using random data? So should I be figuring out 5 corresponding categories, questions, and answers?
-putting the "minimum runable code", does that mean just what I have listed above, as is everything involved with the problem? Or is it every line of code that needs to be run to GET to the problem(in which case would be a LOT more)?
-Am I running what I write in my console? Previously when I ran Reprex I put it at the top of my script, and then when I ran the app it populated the right error message. It says copy your code and then run reprex :: reprex() in the console pane, but I don't really understand that conceptually. That would then make a reproducible example?

No one is usually good at things the first time they do them, and that's likely the case with me here and making a good Reprex. But that's why I can figure the first one out so that going forward I'll know how to do it!

Thanks again,

-Taylor

you should share that here, formatted as code.
and (i know already) but you would indicate that it is your Jeop3column dataframe. you dont need to select the columns by name, if its really a 3 column with only those 3 in it.

you should provide enough of Jeop3col for a meaningful example. if your code requires any minimum amount, like 5, then it would be perverse to provide less, you should provide the minimum that your program needs.

it means eliminating all code that you can eliminate that does not shed light on your issue / is irrelevant. For example if you have many shiny figures plots and panels that display all manner of other things and they are all fine, they should all go. you should have the fewest UI elements possible to represent an 'example' of your problem. then after you understand the solution you were provided you can reason about how to change your real code in light of what you learned.

1 Like

A reprex in the context of a Shiny app it's a special case, please have a look at these more specific resources, to learn how to create one for a shiny app

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.