I have a reactiveVal data.frame inside a shiny app that I'd like to sort. However, the attempt known from standard data.frames failed:
r <- reactiveVal(data.frame(val = c(1,3,2), name = c("Jim", "Anna", "Mouse")))
r(r()[order(r()$val, decreasing = TRUE), ])
Error in .getReactiveEnvironment()$currentContext() : Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)
A full example:
library(shiny)
ui <- fluidPage(mainPanel(textOutput("text")))
server <- function(input, output) {
r <- reactiveVal(data.frame(val = c(1,3,2), name = c("Jim", "Anna", "Mouse")))
# r(r()[order(r()$val, decreasing = TRUE), ])
output$text <- renderText(
paste0("The maximum value is ", r()$val[1],", scored by ", r()$name[1],
". The second place goes to ", r()$name[2]," with a value of ",
r()$val[2]))
}
shinyApp(ui = ui, server = server)
r()[order(r()$val, decreasing = TRUE), ]work? - Cettt