I'm building a shiny dashboard and am making many plots from the same dataset. Instead of making separate server output$name objects for each series that I select, I would like to have one server object with a variable and then pass a variable to each ui object that indicates which series I want it to display.
ui <- dashboardPage(
fluidRow(
column(width = 6,
box(title = "Net Income", width=NULL,
dygraphOutput(outputId = "net_income", height = "300px"))
),
column(width = 6,
box(title = "Accounts Receivable", width=NULL,
dygraphOutput(outputId = "accounts", height = "300px"))
)
) # end ui
Notice the multiple server objects that I'm creating that chooses the series to display from a single object, fcast_data. I'm displaying 10 charts from this dataset, so would have to produce 10 separate server render objects. I would like to create 1 server object with a variable 'series_name' that I could pass from the ui objects to indicate which series I want to display.
server <- function(input, output) {
output$net_income <- renderDygraph({
dygraph(fcast_data %>% select(net_income), group = "my_dash")})
output$accounts_receivable <- renderDygraph({
dygraph(fcast_data %>% select(accounts_receivable), group = "my_dash")})
} # end server
Is there a way that I can make one server object (renderDygraph) that just takes parameters from my ui object (dygraphOutput) to choose different series to display? I know how to do this using selectInputs, but can't figure out how to hard-code variables in the ui object to pass to server.
selectInput()function in your UI. Then pass the string to a single plot - you may need to convert toselect_()given the quotations from the input string.