Error in FUN: cannot coerce type 'closure' to vector of type 'character' [No stack trace available] in R

+1 vote

Error in FUN: cannot coerce type 'closure' to vector of type 'character'
  [No stack trace available]

What to do?

I'm new to R. Below is my code - 

library(shiny)
ui <- fluidPage(
  tabsetPanel(
    tabPanel("Plot", plotOutput(plot)),
    tabPanel("ggplot", plotOutput(ggplot))
  )
)

server <- function(input,output) {
  output$plot = renderPlot({ plot(mpg$hwy,mpg$cty,col = colors(length(mpg$hwy))) })
  output$ggplot = renderPlot({ ggplot(mpg, aes(hwy, cty,fill = year)) + geom_point() + theme_bw() })
}

shinyApp(ui = ui,server = server)
Jul 17 in Data Analytics by ramya
581 views

1 answer to this question.

0 votes

You missed out " " for variables in the plotOutput function.

Write as below - 

library(shiny)
ui <- fluidPage(
  tabsetPanel(
    tabPanel("Plot", plotOutput("plot")),
    tabPanel("ggplot", plotOutput("ggplot"))
  )
)

server <- function(input,output) {
  output$plot = renderPlot({ plot(mpg$hwy,mpg$cty,col = colors(length(mpg$hwy))) })
  output$ggplot = renderPlot({ ggplot(mpg, aes(hwy, cty,fill = year)) + geom_point() + theme_bw() })
}

shinyApp(ui = ui,server = server)
answered Jul 17 by Cherukuri
• 32,260 points

Related Questions In Data Analytics

0 votes
1 answer

Error saying "Error in df$item : object of type 'closure' is not subsettable" when trying to use arules package

Try replacing ID <- c("A123","A123","A123","A123","B456","B456","B456") item <- c("bread", "butter", ...READ MORE

answered Nov 15, 2018 in Data Analytics by Maverick
• 10,040 points
207 views
0 votes
1 answer

How to write a custom function which will replace all the missing values in a vector with the mean of values in R?

Consider this vector: a<-c(1,2,3,NA,4,5,NA,NA) Write the function to impute ...READ MORE

answered Jul 4, 2018 in Data Analytics by CodingByHeart77
• 3,690 points
221 views
0 votes
1 answer

Error saying "could not find function "shinyUI"" in shiny R

Its a small spelling mistake that you've ...READ MORE

answered Nov 28, 2018 in Data Analytics by Maverick
• 10,040 points
506 views
0 votes
1 answer

Error saying "could not find function dashboardPage" in shiny R

Include this line in the code: Library(shinydashboard) READ MORE

answered Nov 28, 2018 in Data Analytics by Maverick
• 10,040 points
309 views
0 votes
1 answer

How to replace all occurrences of a character in a character column in a data frame in R

If you used sub() to replace the ...READ MORE

answered Jun 28 in Data Analytics by anonymous
• 32,260 points
155 views
0 votes
1 answer

R Shiny Error: Object of type 'closure' is not subsettable

The error you mentioned happens when you ...READ MORE

answered Aug 20 in Data Analytics by anonymous
• 32,260 points
290 views