I have this shiny app where I am taking inputs from the user and depending on the type of plot the user wants it will show that plot. But I am unable to take the value of the radio button on the app and use it to draw a specific ggvis plot because the "input$ " value can only be used within a render* function which I am not using here because I am drawing with ggvis.
My ui.R file -
library(ggvis)
shinyUI(fluidPage(
sidebarLayout(
sidebarPanel(
selectInput("Xvar", "Choose X variable", choices = colnames(the.data), selected = colnames(the.data)[[2]] ),
selectInput("Yvar", "Choose Y variable", choices = colnames(the.data), selected = colnames(the.data)[[3]] ),
selectInput("IDvar", "Choose ID variable", choices = colnames(the.data), selected = colnames(the.data)[[4]] ),
uiOutput("choose_COVvar"),
uiOutput("choose_COVn"),
br()
),
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Data Exploration",
uiOutput("plot_type"),
br(),
ggvisOutput("ggvis_xy_plot")),
ggvisOutput("ggvis_profile_plot")
)
)
)
))
the server.R file -
library(ggvis)
library(shiny)
shinyServer(function(input, output, session) {
the.data <<- mtcars
output$plot_type <- renderUI({
fluidRow(
column(4, offset = 1,
radioButtons("PlotMethod", h5("Plot type"), c("XY Scatter plot",
"profile plot"))
)
)
})
flex.data <- reactive({
x.name <- input$Xvar
y.name <- input$Yvar
id.name <- input$IDvar
x.data <- the.data[, x.name]
y.data <- the.data[, y.name]
ID.t <- the.data[, id.name]
new.data <- data.frame(x.data, y.data, ID.t)
})
lb <- linked_brush(keys = 1:nrow(flex.data()), "red")
flex.data %>%
ggvis(~x.data, ~y.data) %>%
layer_points(fill := lb$fill, fill.brush := "red") %>%
lb$input() %>%
layer_points(fill := "red", data = reactive(flex.data()[flex.data()$ID.t %in%
flex.data()[lb$selected(), ]$ID.t, ])) %>%
bind_shiny("ggvis_xy_plot")
flex.data %>%
ggvis(~x.data, ~y.data) %>%
layer_points() %>%
layer_lines() %>%
bind_shiny("ggvis_profile_plot")
})
As you can see, currently both the scatter plot and the line plot is there but I want it to be just one depending on the radio button above, the user has pressed.
Any help will be greatly appreciated. Thanks