当我运行Shiny应用程序时,我无法获得“random_comment”,“best”或“最差”数据。有人能指出我正确的方向吗?
我的ui.R文件是
# 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"))
)
)
))
我的server.R文件是
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" ] )})
}
)
我尝试了一些反应函数,例如renderText和renderTable,但我仍然没有看到输出。
答案 0 :(得分:1)
在ui.R文件中,您应该使用:
textOutput({"random_comment"})
和
textOutput({"m"})
在server.R中,您需要renderText
功能:
output$m <- renderText(length(studentsSay))
和
renderText(as.character(evalDF[ sample(1:m, 1), "comments"]))
您可以查看Shiny tutorial (Display reactive output)了解详情。