Error: object '...' not found, it works but i cannot knit it

hey!

I have such a problem with a code. Actually it works and I can save every data I need. However, I have to do html file and it has error.

To be honest, I even don't understand what is wrong.

saveData <- function(data) {
  data <- as.data.frame(t(data))
  if (exists("responses")) {
    responses <<- rbind(responses, data)
  } else {
    responses <<- data
  }
}

loadData <- function() {
  if (exists("responses")) {
    responses
  }
}
column = c('name_of_book', 'id', 'id_of_book', 'grade_of_user', 'avg_rating', 'not_exist')

# Define the fields we want to save from the form
fields <- c("user_id", "title", "book_id", "rating", "average_rating")

# Shiny app with 3 fields that the user can submit data for
shinyApp(
  ui = fluidPage(
    DT::dataTableOutput("responses", width = 500), tags$hr(),
    
    
    selectInput("user_id", "Column contains id of users:",
                column),

    
    selectInput("title","Column contains name/ title of a book:", 
                column),

      
      selectInput("book_id", "Column contains  id of books:", 
               column),

      
      selectInput("rating", "Column contains  user reviews grades:",
                column),

      
      selectInput("average_rating:","Column contains average rating:",
                column),
      
      actionButton("submit","Submit")
    
  ),
  server = function(input, output, session) {
    
    # Whenever a field is filled, aggregate all form data
    formData <- reactive({
      data <- sapply(fields, function(x) input[[x]])
      data})
    
    # When the Submit button is clicked, save the form data
    observeEvent(input$submit, {
      saveData(formData())
    })
    
    
    # Show the previous responses
    # (update with current response when Submit is clicked)
    output$responses <- DT::renderDataTable({
      input$submit
      loadData()
    })    
    
  
    
  }
)


You asked a question about Knitting, so there is an rmarkdown file involved ?
but you shared an interactive shiny app ...
can you explain ?

I'm a rookie in R, so I might mixed all up.
Am I right that it's possible to rum app in Rmarkdown?
Is it possible to make app as html?
An the last question. What is wrong with my code? Why do I have this error?
thank you in advance

its possible to have rmarkdown be a shiny document, but it wouldnt be a full app like you shared the code for
Chapter 19 Shiny Documents | R Markdown: The Definitive Guide (bookdown.org)
Its also possible to have an app (like you shared the codefor) that knits out some templated rmarkdown to a file from a button press in the app.

What is wrong with my code?

I see nothing wrong with it, I ran it, pressed submit a few times, it worked without errors

Why do I have this error?

What process do you go through to take the above code and get an error from it ?

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.