R Shiny Error: Cannot Coerce Type 'Closure' to Vector of Type 'Double'

r shiny - cannot coerce type 'closure' to vector of type 'double'

Try this:

library(tidyverse)
library(shiny)

df2 <- tibble(years = c(2012,2013,2014,2015))

ui <- fluidPage(
sidebarLayout(
sidebarPanel(
sliderInput("year_range",
"Select Years:",
min = 2012,
max = 2019,
value = c(2012, 2019),
ticks = FALSE)),
mainPanel(tableOutput('table'))
)
)

server <- function(input, output) {


output$table <- renderTable({
filter(df2, years >= input$year_range[1], years <= input$year_range[2])
})
}

shinyApp(ui = ui, server = server)

R shiny cannot coerce type 'closure' to vector of type 'double'

The issue was resolved by using a switch in 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()))

Cannot coerce type 'closure' to vector of type list when creating a lag variable by id

Don't use quotes around the column name.

library(data.table)
TandCtable[, RDexp_pre1 := c(NA, RD_expenses[-.N]), by=id]

If you want lag of different offset length it is better to use shift as suggested by @Waldi instead of appending NA's.

TandCtable[, RDexp_pre1 := shift(RD_expenses, 2), by=id]

Don't understand Cannot Coerce type 'closure' Error

TidySymptoms data has no id column in it. Assuming it's a mistake and you have that already in your data you can do the following changes in the function.

  • There is no need to pass df.new to the function.
  • The column in TidySymptoms is called as word but you are using text in the function.

Try this code.

minus_TextNum <- function(df){

df.new <- mutate(df, text = gsub(x = word, pattern = "[0-9]+|\\(.*\\)", replacement = "")) %>%
unnest_tokens(input = text, output = word) %>%
filter(!word %in% c(stop_words$word, "patient")) %>%
group_by(id) %>%
summarise(text = paste(word, collapse = " "))
return(new.df)
}

minus_TextNum(TidySymptoms)


Related Topics



Leave a reply



Submit