0
votes

I cannot get the "random_comment", "best", nor "worst" data to appear when I run the Shiny app. Can someone point me in the correct direction?

My ui.R file is

    # This Shiny app will allow users to upvote/downvote my teaching evaluation
# comments on the basis of how "useful" each comment is

library(shiny)

shinyUI(fluidPage(
  headerPanel("Rate my Teaching Evaluations!"),

  mainPanel(
    h4("The current comment:"),
    random_comment,

    tabsetPanel(
      tabPanel("About", 
               "...",
               paste("Currently there are", m, "comments in the dataset.", sep = " ")
               ),
      tabPanel("Most Useful Evaluations", tableOutput("best")),
      tabPanel("Least Useful Evaluations", tableOutput("worst"))     
      )    
    )
  ))

and my server.R file is

    library(shiny)

shinyServer(
  function(input, output){
    studentsSay <- readLines("studentsSay.txt")
    output$m <- length(studentsSay)

    evalDF <- data.frame(studentsSay, rep(0,m))
    colnames(evalDF) <- c("comments", "rating")

    output$random_comment <- as.character(evalDF[ sample(1:m, 1), "comments"])

    output$best <-  renderTable({head( evalDF[ order(evalDF$rating), "comments" ] )})
    output$worst <- renderTable({tail( evalDF[ order(evalDF$rating), "comments" ] )})

  }
  )

I have tried some of the reactive functions such as renderText and renderTable, but I am still not seeing the outputs.

1

1 Answers

1
votes

In the ui.R file you should use:

textOutput({"random_comment"})

and

textOutput({"m"})

In the server.R, you need the renderText functon:

output$m <- renderText(length(studentsSay))

and

renderText(as.character(evalDF[ sample(1:m, 1), "comments"]))

You can check the Shiny tutorial (Display reactive output) for more information.