Trying to learn the tricks of getting the Shiny+ggvis combo to do what I want. I think I have read through every single post on this and I'm still stumped on why I can't get the following example to work. So now I must appeal to the gurus :)
library(shiny)
library(ggvis)
shinyUI(fluidPage(
# Application title
titlePanel("Shiny/ggvis Test"),
sidebarLayout(
sidebarPanel(
selectInput("x.var", "X:",choices=names(mtcars),selected='mph'),
selectInput("y.var", "Y:",choices=names(mtcars),selected='hp')
),
mainPanel(
ggvisOutput("theplot")
)
)
))
shinyServer(function(input, output, session) {
selectedData <- reactive({
mtcars[, c(input$x.var, input$y.var)]
})
varNames <- reactive({
names(selectedData())
})
selectedData() %>%
layer_points() %>%
add_tooltip(all_values,"hover") %>%
bind_shiny("theplot")
all_values <- function(x){
if(is.null(x)) return(NULL)
paste0(names(x), ": ", format(x), collapse = "<br />")
}
})
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.)
So somehow I must be accessing something that should be in a reactive, right? But I don't know what.