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 asword
but you are usingtext
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
Dynamically Add Function to R6 Class Instance
Multiple Graphs Over Multiple Pages Using Ggplot
Correlation Corrplot Configuration
Is There a Reason to Prefer Extractor Functions to Accessing Attributes with $
How to Create Design Matrix in R
Adding Text to Ggplot Geom_Jitter Points That Match a Condition
How to Plot the Relative Proportions of Two Groups Using a Fill Aesthetic in Ggplot2
R Xts: Generating 1 Minute Time Series from Second Events
Shiny R Renderplots on the Fly
Dynamically Converting a List of Excel Files to CSV Files in R
How to Use Plyr to Number Rows
Using Geo-Coordinates as Vertex Coordinates in the Igraph R-Package