Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error while executing R code "Cannot coerce type 'environment' to vector of type 'character'"

Tags:

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)

I am getting error "ERROR: cannot coerce type 'environment' to vector of type 'character'" while executing above shiny app code in R studio. Please help me resolve the issue.

like image 414
Harshad Patil Avatar asked Oct 27 '25 09:10

Harshad Patil


1 Answers

You should avoid putting newlines and even spaces after the function names. Refer to style guide or here. Code below works perfectly fine.

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)
like image 161
discipulus Avatar answered Oct 28 '25 23:10

discipulus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!