【发布时间】:2022-01-28 04:11:53
【问题描述】:
我正在尝试根据用户从数据框中选择列来计算卡方,但我不断收到以下错误:
-xtfrm.data.frame(x) 中的警告:不能 xtfrm 数据帧
-表中的错误:所有参数必须具有相同的长度。
library(shinydashboard)
library(shiny)
library(dplyr)
library(DT)
df<-data.frame(HairEyeColor)
Cat1.Variables <- c('Sex','Eye','Hair','Freq')
Cat2.Variables <- c('Eye','Hair','Sex','Freq')
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
selectInput('cat1', choices = Cat1.Variables, label = 'Select Category options:'),
selectInput('cat2', choices = Cat2.Variables, label = 'Select Category2 options:')
),
mainPanel(
tableOutput('results')
)
)
)
server=shinyServer(function(input, output) {
datachisquare <- reactive({
req(input$cat1,input$cat2)
df %>% table(list(.data[[input$cat1]]),list(.data[[input$cat2]]))
})
output$results <- renderPrint({
cat(sprintf("\nThe results Chisquare Test are\n"))
print(chisq.test(datachisquare()))})
})
shinyApp(ui, server)
【问题讨论】:
-
你可以试试
df %>% {table(.[[input$cat1]], .[[input$cat2]])}
标签: r shiny shinydashboard chi-squared