2017-12-27 7 views
0

私はselectInputからの入力を挿入することにより、plotpchパラメータを変更しようとしている」:R「double」の

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

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

、私はエラーが発生します: 'double'型のベクトルに型 'クロージャー'を強制することはできません。この問題を解決するにはどのような手順を取る必要がありますか?もちろん、求職とセックスの両方が要因です。 全コード:

library(shiny) 
library(Ecdat) 
attach(Benefits) 

u <- shinyUI(pageWithSidebar(
    headerPanel("Social benefits"), 
    sidebarPanel(

    selectInput("variable1", "Zmienna X:", 
       list("Bezrobocie" = "stateur", 
        "Max zasilek" = "statemb", 
        "Wiek" = "age", 
        "Staz w bezrobociu" = "tenure", 
        "Replacement rate" = "rr" 
       )), 

    selectInput("variable2", "Zmienna Y:", 
       list("Bezrobocie" = "stateur", 
        "Max zasilek" = "statemb", 
        "Wiek" = "age", 
        "Staz w bezrobociu" = "tenure", 
        "Replacement rate" = "rr" 
       )), 
    selectInput("points", "Punkty:", 
       list("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" 

       )), 
    checkboxInput("reg", "Pokaz krzywa regresji", FALSE) 


), 
    mainPanel(
    plotOutput("Plot") 
) 

)) 

s <- shinyServer(function(input, output) 
{ 


    formula <- reactive({paste(input$variable2,"~",input$variable1)}) 

    caption <- renderText({formula()}) 

    pkt <- reactive({input$points}) 

    #pkt <- renderText({paste(input$points)}) 

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

    if(input$reg == TRUE){ 
     abline(lm(as.formula(formula())),col ="red", lwd = 2) 
     legend("topleft",inset = 0.02, legend = "Krzywa regresji", 
      col="red",lty = 1, lwd = 2) 

    } 
    }) 

}) 
shinyApp(u,s) 
+1

完全なアプリのコードを入力してください。このエラーメッセージは、入力変数とは関係ありません。 –

+1

'input $ points'は' as.numeric(input $ points) 'を' NA'にする数ではありません。したがって、エラー。 – SBista

答えて

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())) 
関連する問題