执行R代码时出错“无法将类型'环境'强制转换为'字符'类型的向量

时间:2017-02-13 06:30:58

标签: r shiny

require(shiny)
setwd("C://Users//Harshad//Desktop//Equiskill - BA")
cars <- read.table(file = "cars.csv", sep = ",", header = TRUE, quote="")

var_list <- as.character(names(cars))


ui <- fluidPage
(
  selectInput(inputId = "var",label = "Select Dependent Variable:",choices =    c(var_list))
)

server <- function(input,output)
{
}

shinyApp(ui <- ui, server <- server)

我收到错误“错误:在R studio中执行上面闪亮的应用程序代码时,不能强制类型'字符'的向量类型'环境'。请帮我解决这个问题。

1 个答案:

答案 0 :(得分:3)

您应该避免在函数名称后添加newlines甚至spaces。请参阅style guidehere。下面的代码完全正常。

require(shiny)
# load your data I am using default mtcars data here
cars <- mtcars

var_list <- as.character(names(cars))

ui <- fluidPage(
        selectInput(inputId = "var",label = "Select Dependent Variable:", choices = c(var_list))
    )

server <- function(input,output)
{
}

shinyApp(ui = ui, server = server)