2015-04-26 133 views
0

當我運行Shiny應用程序時,我無法獲得「random_comment」,「best」或「worst」數據。有人能指出我正確的方向嗎?閃亮的多輸出

我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,但我仍然不看到輸出。

回答

1

在ui.R文件,你應該使用:

textOutput({"random_comment"}) 

textOutput({"m"}) 

在server.R,需要renderText functon:

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

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

您可以檢查Shiny tutorial (Display reactive output)瞭解更多信息。