r - Error: cannot coerce class "c("reactiveExpr", "reactive")" to a data.frame -


i'm new r, shiny, , coding in general , have question. i've been reading through similar questions , cannot shiny app function based on answers. basically, want user able enter in numeric inputs, put inputs data frame, , output plots. here relevant part of code ui:

ui <- fluidpage( titlepanel("iq plots"), sidebarlayout( sidebarpanel(   numericinput(inputid = "fsiq",                label = "fsiq",                min = 40, max = 160, value = 100),   numericinput(inputid = "vci",                label = "vci",                min = 40, max = 160, value = 100),   numericinput(inputid = "vsi",                label = "vsi",                min = 40, max = 160, value = 100),   numericinput(inputid = "fri",                label = "fri",                min = 40, max = 160, value = 100),   numericinput(inputid = "wmi",                label = "wmi",                min = 40, max = 160, value = 100),   numericinput(inputid = "psi",                label = "psi",                min = 40, max = 160, value = 100) 

and here server:

server <- function(input, output) { ### set dataframe index <- c("vci", "vsi", "fri", "wmi", "psi") index_score <- c(vci, vsi, fri, wmi, psi) index_verbal <- c("verbal", "non-verbal", "non-verbal", "verbal", "non-verbal") index_auto <- c("mediated", "mediated", "mediated", "automatic", "automatic") index.data <- data.frame(index, index_score, index_verbal, index_auto)  newindex_score <- reactive({c(input$vci, input$vsi, input$fri, input$wmi, input$psi)}) newindex.data <- reactive({data.frame(index, newindex_score, index_verbal, index_auto)})  output$iqplot <- renderplot({ library(ggplot2) ggplot(data = iqdist, aes(x = ndist, y = iqy)) +   fdist +    ggtitle("full scale iq") +   xlab("iq score") +   ylab("frequency") +   scale_x_continuous(limits = c(40,160), breaks = seq(55,145,15)) +   geom_segment(aes(x=input$fsiq, y = 0, xend=input$fsiq,                    yend = dnorm(input$fsiq, iqmean, iqsd)),                color = "blue", size = 2) +   theme(axis.text.y = element_blank(),         axis.ticks = element_blank()) +   geom_ribbon(data=subset(iqdist, ndist > 85 & ndist < 115),               aes(ymax=iqy),ymin=0,fill="green", alpha = 0.3) +   geom_ribbon(data=subset(iqdist, ndist > 70 & ndist < 85),               aes(ymax=iqy),ymin=0,fill="yellow", alpha = 0.3) +   geom_ribbon(data=subset(iqdist, ndist > 115 & ndist < 130),               aes(ymax=iqy),ymin=0,fill="yellow", alpha = 0.3) +   geom_ribbon(data=subset(iqdist, ndist <= 70.5),               aes(ymax=iqy),ymin=0,fill="red", alpha = 0.3) +   geom_ribbon(data=subset(iqdist, ndist > 130),               aes(ymax=iqy),ymin=0,fill="red", alpha = 0.3) +   scale_y_continuous(limits = c(0,.03), expand = c(0,0)) +   expand_limits(y=0) +   geom_segment(aes(x = 100, y = 0, xend = 100,                    yend = iqy), color = "red", size = 1) +   annotate('text', x = 100, y = 0.01,            label = "<------------average------------>", col = "black") })  output$indplot <- renderplot({ library(ggplot2) newindex.data()$index <- factor(newindex.data()$index, levels = c("vci", "vsi", "fri", "wmi", "psi")) newindex.data()$index <- factor(newindex.data()$index,                            levels = newindex.data()$index[order(newindex.data()$index)]) indplot <- ggplot(data = newindex.data(), x = index, y = newindex_score()) +   ggtitle("index scores") +   xlab("wisc-v index") +   ylab("standard score") +   scale_y_continuous(limits = c(0,160), breaks = seq(10,160,15),                      expand = c(0,0)) +   geom_rect(data = newindex.data(), aes(x = index, y = newindex_score()),             xmin = as.numeric(newindex.data()$index[[1]]) - 1,             xmax = as.numeric(newindex.data()$index[[5]]) + 1,             ymin = 85,             ymax = 115,             fill = "green",             alpha = 0.1) +   geom_rect(data = newindex.data, aes(x = index, y = newindex_score()),             xmin = as.numeric(newindex.data()$index[[1]]) - 1,             xmax = as.numeric(newindex.data()$index[[5]]) + 1,             ymin = 70,             ymax = 85,             fill = "yellow",             alpha = 0.1) +   geom_rect(data = newindex.data(), aes(x = index, y = newindex_score()),             xmin = as.numeric(newindex.data()$index[[1]]) - 1,             xmax = as.numeric(newindex.data()$index[[5]]) + 1,             ymin = 115,             ymax = 130,             fill = "yellow",             alpha = 0.1) +   geom_col(aes(x = index, y = newindex_score()), fill = "blue4") +   geom_hline(yintercept = 100, color = "red", size = 2) indplot }) } 

the first plot "iqplot" works, think because it's 1 input plot needs react rather 5 inputs need put data frame. second plot, "indplot" keeps appearing error: cannot coerce... can seen in code, tried putting () after data frame, in newindexdata()$index, rather newindexdata$index no luck. appreciated , apologize if question basic!


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -