スーパーで新しいシャイニーです。私はさまざまな相関/一致係数と表示グラフを計算するアプリケーションを開発しようとしています。uiドロップダウンメニューの選択肢をサーバーの出力にリンクする方法
テストの選択肢をドロップダウンメニューからリンクする方法がわかりません。現時点では、私は3つの選択肢(Spearman、Pearson、Kendall)でcorを使って相関テストを行うことしかできません。私はCohenのκテスト(パッケージfmsbとコマンドKappa.test(selectedData())を使用しています)を組み込みたいと思います。私はrenderPrintコマンドの中にKappaを組み込むためにelse文を使用しようとしましたが、エラーメッセージが出ます。
この段階では、各テストにどのような適切な変数を使用するかについてはあまり心配していません。私は以下のコードを投稿します。
おかげ
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')
)
)
)
Server.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'関数は依然としてそのメソッドだけをとります。新しい選択肢を別々に処理する必要があります。 – Gopala