Monitoring survey with R Shiny dashboards

We are developing a R shiny dashboard to monitor our survey. To download the latest data, we use the SurveySolutionAPI package. We have a .R file that has the following code to import the data. We source this file in the shiny app.

#SuSo Api keys
suso_set_key(suso_server = "server.link", suso_user = "api", suso_pass = "xxxxxx")

#Version 1
v1 <- suso_export(server = suso_get_api_key("susoServer"),
                  apiUser = suso_get_api_key("susoUser"),
                  apiPass = suso_get_api_key("susoPass"),
                  questID = "xxxx",
                  reloadTimeDiff = 1,
                  version = 1,
                  inShinyApp = F)
#Version 2
v2 <- suso_export(server = suso_get_api_key("susoServer"),
                  apiUser = suso_get_api_key("susoUser"),
                  apiPass = suso_get_api_key("susoPass"),
                  questID = "xxxx",
                  reloadTimeDiff = 1,
                  version = 2,
                  inShinyApp = F)
#Version 3
v3 <- suso_export(server = suso_get_api_key("susoServer"),
                  apiUser = suso_get_api_key("susoUser"),
                  apiPass = suso_get_api_key("susoPass"),
                  questID = "xxxx",
                  reloadTimeDiff = 1,
                  version = 3,
                  inShinyApp = F)

#Extracting main interviews
w1_v1 <- v1[["main"]][["w1"]]
w1_v2 <- v2[["main"]][["w1"]]
w1_v3 <- v3[["main"]][["w1"]]

#Merging data
data <- union(w1_v1,w1_v2)
data <- union(data,w1_v3)

This takes a while every time we load the dashboard, as new data is generated and downloaded in the background. The suso_export command has an option inShinyApp = T. This should technically show a progress indicator for the download status.

This doesn’t seem to work for us. We get this error:
Error in incProgress(0.1) : 'session' is not a ShinySession object.

I am sure we are missing a critical step. Can someone suggest how to implement this progress indicator in the shiny app?

1 Like

I was able to get around this issue by adding withProgress around the code. I also had to include this import script within shiny app (ui / server) and assigned this to a button to update when clicked.

#Version 1
withProgress(message = 'Getting version 1 data', value = 0, {
v1 <- suso_export(server = suso_get_api_key("susoServer"),
                  apiUser = suso_get_api_key("susoUser"),
                  apiPass = suso_get_api_key("susoPass"),
                  questID = "xxxx",
                  reloadTimeDiff = 1,
                  version = 1,
                  inShinyApp = T)
})

PS: I now realise this is a wrong place for this question as it is less SS question and more of an R question. I hope this helps someone deploying SS in R shiny.

1 Like