ř光泽不能强制类型“闭合”到类型的矢量“双重”

我试图通过插入输入从selectInput修改的plotpch参数:ř光泽不能强制类型“闭合”到类型的矢量“双重”

selectInput("points", "Points:", 

list("Job lost" = "joblost",

"Sex" = "sex",

))

output$Plot <- renderPlot({ 

plot(as.formula(formula()),data=Benefits,

main = caption(), pch = as.numeric(input$points),

col=as.numeric(input$points))

})

不幸的是,我得到一个错误:不能将类型'closure'强制为'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)

回答:

的问题是使用一个开关在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()))

以上是 ř光泽不能强制类型“闭合”到类型的矢量“双重” 的全部内容, 来源链接: utcz.com/qa/264654.html

回到顶部