Firstly, here is a minimal reproducible example:
Suppose I have the following example.Rmdflexdashboard application :
---
title: "Test App"
output:
flexdashboard::flex_dashboard:
theme: ["lumen"]
orientation: ["columns"]
runtime: shiny
---
```{r setup, include=FALSE}
source('modules.R')
```
Test
==================
Inputs {.sidebar data-width=250}
------------------
```{r}
globalInputs <- callModule(setup, "inputs")
callModule(chart, "modalChart", globalInputs)
sidebar("inputs")
```
Column
-------------------------------------
```{r}
chartUI2("modalChart")
```
Here is my modules.R file :
sidebar <- function(id) {
ns <- NS(id)
tagList(
helpText("Press the button below to pull up a modal:"),
actionButton(ns("settings"), "Settings", icon = icon("cogs"), width = '100%')
)
}
setup <- function(input, output, session) {
return(input)
}
modalUI <- function(id) {
ns <- NS(id)
withTags({
fluidPage(
fluidRow(sliderInput(ns("bins"), "Number of bins:",
min = 1, max = 50, value = 30),
textInput(ns("plotTitle"), label = "Plot Title", value = "This is a test")
))
})
}
modalFooterUI <- function(id) {
ns <- NS(id)
tagList(
modalButton("Cancel", icon("remove")),
actionButton(ns("modalApply"), "Apply", icon = icon("check"))
)
}
chartUI2 <- function(id) {
ns <- NS(id)
plotOutput(ns("distPlot"))
}
chart <- function(input, output, session, setup) {
observeEvent(setup$settings, {
showModal(modalDialog(
modalUI("inputs"),
title = "Settings",
footer = modalFooterUI("inputs"),
size = "l",
easyClose = TRUE,
fade = TRUE)
)
})
output$distPlot <- renderPlot({
if (setup$settings == 0)
return(
hist(faithful[, 2],
breaks = 5,
main = 'This is the default title',
col = 'darkgray',
border = 'white')
)
isolate({
x <- faithful[, 2]
bins <- setup$bins
hist(x,
breaks = bins,
main = setup$plotTitle,
col = 'darkgray',
border = 'white')
})
})
}
Here I want to execute:
- When the page loads the rendering
distPlotwith default options. This should always happen. - When I click "Settings"
actionButton, it issues a modal overlay (but keeps the chart in the background in its original state) - Allow the user to change the parameters in the pop-up module, but do not redraw the graph until the user clicks the "Apply" button.
, # 1 , "", Invalid breakpoints produced by 'breaks(x)': NULL. , ( , actionButton (, , ).
?
!!