[:尺寸不正确(执行闪亮的R代码)中的错误

  • 本文关键字:代码 错误 不正确 执行 r shiny
  • 更新时间 :
  • 英文 :


我在执行闪亮代码时会遇到错误的错误:grepl:grepl中的错误:grepl:Informe'pattern'参数"one_answers" errir [:in ui dimungect in congement''(In In Inmungect in congement''(In In Inmungect of dimumbers''(IN UI)。请帮忙。以下是代码的片段。当我说出最后一行时,我会遇到错误

  library(MASS)
  library(shinythemes)
  library(shiny)
  library(ggplot2)
  mass.tmp <- data(package = "MASS")[3]
  mass.datasets <- as.vector(mass.tmp$results[,3])
  ui <- fluidPage(
    theme = shinytheme("superhero"),
    titlePanel("Linear Regression Modelling"),
    sidebarLayout(
      sidebarPanel(
        selectInput("dsname", "Dataset:",choices = c(mass.datasets)),
        uiOutput("y_axis"),
        uiOutput("x_axis")
      )     ,
      mainPanel(
        tags$br(),
        tags$br(),
        "R-squared:",
        tags$span(tags$b(textOutput("rsquared")),style="color:blue")
      )
    )
  )
  server <- function(input, output) {
    output$x_axis <- renderUI({
      col_opts <- get(input$dsname)
      selectInput("x_axis2", "Independent Variable:", choices = c(names(col_opts)))
    })
    cols2 <- reactive({
      col_opts2 <- get(input$dsname)
      #names(col_opts2)[!grepl(input$x_axis2, names(col_opts2))]
    })
    output$y_axis <- renderUI({
      selectInput("y_axis2", "Dependent Variable:", choices = c(names(cols2())))
    })
    model <- reactive({
       #lm(input$dsname[,names(input$dsname) %in% input$y_axis2] ~ input$dsname[,names(input$dsname) %in% input$x_axis2])
       #tmp <- paste(input$y_axis2,"~",input$x_axis2,sep = " ")
        lm( input$y_axis2 ~ input$x_axis2 , data = input$dsname ) 
    })
    model_summary <- reactive({summary(model())})
    output$rsquared <- renderText({  model_summary()$r.squared   }) 
  }
  shinyApp(ui = ui, server = server)

是的,那更好。有多个错误:我们不应该为您调试所有这些,但这里有很多指示。那应该帮助您全部找到它们。

1)您正在使用:input$x_axisinput$y_axis,但最后用" 2"定义了它。因此适应。

2)您应该定义:

cols2 <- reactive({ col_opts2 <- get(input$dsname) names(col_opts2)[!grepl(input$x_axis2, names(col_opts2))] })

renderUI功能之外。

3)此外,这个片段似乎有问题: names(col_opts2)[!grepl(input$x_axis2, names(col_opts2))]

最后,我会检查您是否产生无效并禁止!is.null()

编辑:问题更新:

您试图通过字符串构建lm()公式,您可以在Shiny之外进行测试:无法正常工作。您应该使用 formula()功能,并提出类似的类似功能:

lm(formula(paste(input$y_axis2, input$x_axis2, sep =" ~ ")), data = get(input$dsname))

最新更新