Allow for users to add UI and server code to shiny application. Hopefully can be done in a module.
I am not sold if a complete refresh is the best approach... would be nice to just update the rlog information.
library(reactlog)
library(shiny)
options(shiny.reactlog = TRUE)
# Define UI for app that draws a histogram ----
ui <- fluidPage(
# App title ----
titlePanel("Hello Shiny!"),
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
# Input: Slider for the number of bins ----
sliderInput(inputId = "bins",
label = "Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Main panel for displaying outputs ----
mainPanel(
# Output: Histogram ----
plotOutput(outputId = "distPlot"),
)
),
### start
actionButton("refreshReactlog", "Refresh Reactlog", style=""),
uiOutput("reactlogframe")
### end
)
# Define server logic required to draw a histogram ----
server <- function(input, output, session) {
# Histogram of the Old Faithful Geyser Data ----
# with requested number of bins
# This expression that generates a histogram is wrapped in a call
# to renderPlot to indicate that:
#
# 1. It is "reactive" and therefore should be automatically
# re-executed when inputs (input$bins) change
# 2. Its output type is a plot
output$distPlot <- renderPlot({
x <- faithful$waiting
bins <- seq(min(x), max(x), length.out = input$bins + 1)
hist(x, breaks = bins, col = "#75AADB", border = "white",
xlab = "Waiting time to next eruption (in mins)",
main = "Histogram of waiting times")
})
### start
output$reactlogframe <- renderUI({
# trigger refresh
input$refreshReactlog
htmltools::tagList(
htmltools::tags$iframe(id = "reactlog_iframe",width = "100%", height = 600),
htmltools::tags$script(HTML("
(function() {
var src = 'reactlog?w=' + window.escape(window.Shiny.shinyapp.config.workerId) + '&s=' + window.escape(window.Shiny.shinyapp.config.sessionId);
console.log('src:', src);
$('#reactlog_iframe').attr('src', src);
})()
"))
)
})
### end
}
# Create Shiny app ----
shinyApp(ui = ui, server = server)
Allow for users to add UI and server code to shiny application. Hopefully can be done in a module.
I am not sold if a complete refresh is the best approach... would be nice to just update the rlog information.