R闪亮不能强迫类型'关闭'到'' double'类型的向量

时间:2017-12-27 11:32:47

标签: r shiny

我'尝试通过插入pch的输入来修改plot的{​​{1}}参数:

selectInput

selectInput("points", "Points:",
                list("Job lost" = "joblost",
                     "Sex" = "sex",                  
                ))

不幸的是,我收到了一个错误:无法强制类型'关闭'到'' double'类型的向量。我应该采取什么措施来解决这个问题?当然,工作和性别都是因素。 完整代码:

output$Plot <- renderPlot({
    plot(as.formula(formula()),data=Benefits,
         main  = caption(), pch = as.numeric(input$points), 
         col=as.numeric(input$points))
})

1 个答案:

答案 0 :(得分:0)

使用selectInput中的开关

解决了该问题
 pkt <- reactive({
    switch(input$points,
           "Powod utraty pracy" = joblost,
           "Plec" = sex,
           "Nie-bialy" = nwhite,
           ">12 lat szkoly" = school12,
           "Robotnik fizyczny" = bluecol,
           "Mieszka w miescie" = smsa,
           "Zonaty" = married,
           "Ma dzieci" = dkids,
           "Male dzieci" = dykids,
           "Glowa rodziny" = head,
           "Otrzymuje zasilki" = ui)
  })

  txt <- renderText({paste(input$points)})

  output$Plot <- renderPlot({
    plot(as.formula(formula()),data=Benefits,
         main  = caption(), pch = as.numeric(pkt()), 
         col=as.numeric(pkt()))