如何在闪亮中显示混淆矩阵

时间:2015-03-02 00:11:53

标签: r shiny

我正在尝试此代码,但它没有显示任何内容:

ui.R:

mainPanel(width = 4,
      tabsetPanel(
        #tabPanel("Plot", plotOutput("plot")),
        tabPanel("Result", selectInput("featureEx", "Feature Exploration",
                                       c("ABC", "AB", "AC", "A"), multiple = TRUE),
                          plotOutput("fePlot"),dataTableOutput("confusionmatrix")),

        tabPanel("Wiki", verbatimTextOutput("Wiki")),
        tabPanel("Plots", tableOutput("plots"))
      )
    ))

server.R:

#Create Confusion Matrix of Predictions
  ref = matrix(c("P", "N", "P", "P", "P", "P","N"), ncol=1)
  pred = matrix(c("P", "N", "N", "P", "P", "P","P"), ncol=1)
  output$confusionmatrix <- renderPrint({
    confusionMatrix(ref,pred)
  })

我应该使用dataTableOutput或tableOutput以外的其他东西来显示confusionmatrix的结果吗?

2 个答案:

答案 0 :(得分:3)

我遇到了同样的问题,我在ui.R文件中使用了以下命令:

mainPanel(
helpText("Prediction Results Using Testing data"),
verbatimTextOutput('output')
)

工作正常

斯特凡诺

答案 1 :(得分:0)

您可以使用UI组件中的verbatimTextOutput命令和Server组件中的renderPrint在Rshiny中显示混乱矩阵。

简单的例子

# Have these two line in app.R file
predicted <- c(1,1,1,1,0,0,0,0) 
Actual <- c(1,1,1,0,1,0,0,0)

# in UI component have below item to display confusion matrix
verbatimTextOutput(outputId = "modelsumr")

# in server component 
output$cnfmatrs <- renderPrint({
  table(predicted,Actual)
}