I set up a basic app equipped with a checkboxInput that can be toggled to display the source code (both ui.R and server.R). It works locally, but I'm having problems setting it up on the server:
The main problem is that the app does not "source" the ui.R and server.R. It gives me:
I have saved the ui.R and server.R inside a /www/ subfolder, where they can be found at this time, although with some delay and not at every attempt.
Code copied below.
# server.R
library("shiny")
library("shinyAce")
shinyServer(
function(input, output) {
# A reactiveValues object holds the value of the counter
values <- reactiveValues(i = 0)
# Print the value of the counter stored in values$i
output$count <- renderUI({
h5(paste0("counter = ", values$i))
})
# Show the source code
output$source <- renderUI({
if (input$showCode) {
list(
aceEditor("ui"
, value = paste(readLines(paste0(sourceFilePath,"ui.R")), collapse="\n")
, mode = "r"
, theme = "cobalt"
, height = "260px"
, readOnly = TRUE
),
aceEditor("server"
, value = paste(readLines(paste0(sourceFilePath,"server.R")), collapse="\n")
, mode = "r"
, theme = "cobalt"
, height = "260px"
, readOnly = TRUE)
)
} else {
return(invisible())
}
})
# Display buttons in the mainPanel
output$buttons <- renderUI({
if (values$i == 0) {
list(actionButton("increment", "Next"))
} else {
if (values$i == 10) {# bugs: if you click too fast it will jump to 11, 12, etc.
list(actionButton("decrement", "Back"))
} else {
list(actionButton("decrement", "Back"), actionButton("increment", "Next"))
}
}
})
# The observers re-run the code whenever the button is clicked
# Use isolate to avoid getting stuck in an infinite loop
observe({
if(is.null(input$increment) || input$increment == 0){return()}
values$i <- isolate(values$i) + 1
})
observe({
if(is.null(input$decrement) || input$decrement == 0){return()}
values$i <- isolate(values$i) - 1
})
}
)