Error publishing R shiny app

I am attempting to publish an update to an R Shiny app I already coded of a Jeopardy! quiz, link below to what I currently have.

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

I want to make an update where the correct answers are printed at the bottom of the page, below where the "YOU GOT A BLANK" message now is.

I have updated the code that works with a section that SHOULD print the correct answers, code is below...

#
# 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")
    
    
    
    
    
)
#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 = "C:/Users/taylo/OneDrive/Documents/jeop3column.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")
            )
        })
    })
 
    observeEvent(input$submit_answers, {
        num_right <- 0
        
        
      
        # 
        output$number_correct <- renderUI({
            paste("Percentage correct", "YOU GOT A: ", num_right)
        
        output$correct_answers <- renderUI({
            paste("Question 1 Answer", single_cat_gen$question[1])
            paste("Question 2 Answer", single_cat_gen$question[2])
            paste("Question 3 Answer", single_cat_gen$question[3])
            paste("Question 4 Answer", single_cat_gen$question[4])
            paste("Question 5 Answer", single_cat_gen$question[5])    
        
        })
    })
    
    
   
    
    
    }
}

shinyApp(ui = ui, server = server)

I tried running the app but get the error message posted below of unmatched ")" in the shinyApp section.

215: shinyApp
     ^
Error in sourceUTF8(fullpath, envir = new.env(parent = sharedEnv)) : 
  Error sourcing C:\Users\taylo\AppData\Local\Temp\RtmpUP8N9d\file60047f45a4b

I have tried going back to my other working app and finding the equivalent brackets and matching them up to no avail, along with clicking and following each one in an attempt to find where it is missing.

Where I am at is I get the error message listed above, and highlights of unmatched brackets...

HERE
observeEvent**(**input$submit_answers, {

HERE
}))

and HERE
shinyApp(ui = ui, server = server**)**

Somewhat of a loss of how else to troubleshoot, anyone have any advice/ideas feel free to share!

Thanks,

-Taylor

Is it a typo or your username is really taylo?

your last two closing curly brackets need a regular closing bracket right in the middle of them

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

-->

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

username is taylo!

probably should change that lol

hi @nirgrahamuk

That worked! Thanks so much, appreciate the help.

-Taylor

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