【发布时间】:2015-05-04 22:32:23
【问题描述】:
如何在 Shiny 的 mainPanel 的结果选项卡上输出函数的结果(比如 caret 包中的混淆矩阵)?
这是我在 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$confusionMat <- renderPrint({
confusionMatrix(ref,pred)
})
这就是我在 ui.R 中的内容:
mainPanel(width = 4,
tabsetPanel(
#tabPanel("Plot", plotOutput("plot")),
tabPanel("Result", selectInput("featureEx", "Feature Exploration",
c("ABC", "AB", "AC", "A"), multiple = TRUE),
helpText("Prediction Results Using Testing data"),
dataTableOutput("confusionMat"),
capture.output("confusionMat"),
plotOutput("fePlot")
),
当我在 RStudio 中输入函数时,得到的结果是:
> confusionMatrix(ref,pred)
Confusion Matrix and Statistics
Reference
Prediction N P
N 1 1
P 1 4
Accuracy : 0.7143
95% CI : (0.2904, 0.9633)
No Information Rate : 0.7143
P-Value [Acc > NIR] : 0.6792
Kappa : 0.3
Mcnemar's Test P-Value : 1.0000
Sensitivity : 0.5000
Specificity : 0.8000
Pos Pred Value : 0.5000
Neg Pred Value : 0.8000
Prevalence : 0.2857
Detection Rate : 0.1429
Detection Prevalence : 0.2857
Balanced Accuracy : 0.6500
'Positive' Class : N
所以我想在一个格式良好的闪亮矩阵中显示混淆表,我希望能够使用 outputTable 来做到这一点,它不显示任何内容,并在结果选项卡中也显示纯文本。目前主面板中没有显示任何内容。有什么解决办法吗?
【问题讨论】:
-
我可以提出建议并请您提供single-file shiny 以便我们可以轻松运行代码并查看结果吗?我将提供一个解决方案,但由于您尚未提供完整代码,因此无法重现
标签: r shiny confusion-matrix