Reputation: 799
I have reactive value which is data.frame and want to:
I don't uderstand why my code doesn't work:
library(shiny)
ui <- fluidPage(actionButton("printMean", "print mean"),
actionButton("setZeroToSepal.Length", "setZeroToSepal.Length"))
dt <- iris
server <- function(input, output){
values <- reactiveValues(x = dt)
observeEvent(input$printMean, {
d <- values$x
showNotification(mean(d$Sepal.Length), type = "default")
})
observeEvent(input$setZeroToSepal.Length, {
values$x$Sepal.Length <- rep(0, nrow(values$x))
})
}
shinyApp(ui, server)
the error is: Error in $: $ operator is invalid for atomic vectors
Upvotes: 1
Views: 64
Reputation: 26258
The issue is with showNotification
. I believe it's expecting a character, although it's not well documented, and looking through the source code I can't confirm this. You can use
showNotification(as.character(mean(d$Sepal.Length)), type = "default")
and it should work.
Upvotes: 1