【发布时间】:2016-08-27 21:09:05
【问题描述】:
Shiny 的超级新手。我正在尝试开发一个应用程序来计算不同的相关/一致性系数以及显示图表。
我不知道如何从下拉菜单中链接我的测试选项。在这一点上,我只能使用带有三个选项的 cor 进行相关性测试 - Spearman、Pearson 和 Kendall。我想合并 Cohen 的 kappa 测试(使用包 fmsb 和命令 Kappa.test(selectedData()))。我尝试使用 if else 语句将 Kappa 合并到 renderPrint 命令中,但我不断收到错误消息。
在这个阶段,我不太关心每个测试使用什么合适的变量。我在下面发布我的代码。
谢谢
library(shiny)
# Loading package for Kappa test
library(fmsb)
# Generating simulated data
dat <- as.data.frame(dat)
UI.R
ui <- fluidPage(
pageWithSidebar(
headerPanel('Correlation coefficient and scatter plots'),
sidebarPanel(
selectInput('xcol', 'X Variable', names(dat)),
selectInput('ycol', 'Y Variable', names(dat),
selected=names(dat)[[2]]),
selectInput(inputId = "measure", label = "Choose the correlation measure that you want to use",
choices = c("Spearman correlation" = "spearman",
"Pearson correlation" = "pearson",
"Kendall's W" = "kendall",
"Cohen's kappa" = "kappa"))
),
mainPanel(
plotOutput('plot1'),
verbatimTextOutput('stats')
)
)
)
服务器.R
server <- function(input, output){
# Combine the selected variables into a new data frame
selectedData <- reactive({
dat[, c(input$xcol, input$ycol)]
})
output$plot1 <- renderPlot({
plot(selectedData(),pch = 20, cex = 3, col = "red")
})
output$stats <- renderPrint({
round(cor(selectedData(), method = input$measure), 3)
})
}
shinyApp(ui = ui, server = server)
【问题讨论】:
-
cor函数仍然只采用它所做的方法。您需要单独处理这个新选择。
标签: r shiny-server shiny