I'm setting up a web application with shiny dashboard in order to display data from google analytics. I would like to let the user choose in which plot he wants to display the data by a form (plot1, plot2, plot3). I want to retrieve the location (input$select_plot) and generate the data in the selected plot when i click on action button (something like output$(input$select_plot)) :
I tried different ways (with reactive) but still don't work, i don't know if it is even possible
Here is my code :
ui.R
tabItem("perso2", h1("Sub-item 2 tab content"),
hr(),
fluidRow(
column(3, wellPanel(
selectInput("select2", label = h3("Metrics"),
multiple = TRUE,
choices = list("Users" = "users",
"New users" = "newUsers",
"Sessions" = "sessions",
"Session Duration" = "sessionDuration",
"Average session" = "avgSessionDuration"),
selected = 1),
selectInput("select_plot", label = h3("Select box"),
choices = list("Choice 1" = "plot1", "Choice 2" = "plot2", "Choice 3" = "plot3")),
actionButton("do", "Click Me")
))),
fluidRow(
column(width = 4, plotOutput("plot1")),
column(width = 4, plotOutput("plot2")),
column(width = 4, plotOutput("plot3"))
)
)
and server.R
dataaa <- eventReactive(input$do, {
token <- auth$token()
time <- rollupGA(GAProfileTable = getprofile(),
start_date = "2019-04-04",
end_date = "2019-04-11",
metrics = paste("ga:",input$select2, collapse=NULL, sep=""),
ga = token)
time[,c('date',input$select2)]
})
selected_plot <- reactive({ input <- select_plot })
output$selected_plot <- renderPlot({
validate(
need(getprofile(), "Authentificate to see"))
plot(dataaa())
})
If the user choose "Choice 3", I expect to generate a plot in plotOutput("plot3"), Is there a solution or another way to do this ?
Thks