-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
272 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
|
||
#' Block / unblock an UI element | ||
#' | ||
#' @param id Id of the element to block, for exemple an `outputId`. | ||
#' @param text Text displayed below the blocking indicator. | ||
#' @param type Type of blocking indicator. | ||
#' @param ... Other configuration option, see [online documentation](https://notiflix.github.io/documentation#DocsBlock). | ||
#' @param selector Custom CSS selector, if used `id` is ignored. | ||
#' @param session Default Shiny session. | ||
#' | ||
#' @return No value. | ||
#' @export | ||
#' | ||
#' @name block | ||
#' | ||
#' @example examples/block.R | ||
block <- function(id, | ||
text = "Loading", | ||
type = c("standard", "hourglass", "circle", "arrows", "dots", "pulse"), | ||
..., | ||
selector = NULL, | ||
session = shiny::getDefaultReactiveDomain()) { | ||
type <- match.arg(type) | ||
insertUI( | ||
selector = "html", | ||
ui = tagList(html_dependency_block()), | ||
immediate = TRUE, | ||
where = "afterBegin", | ||
session = session | ||
) | ||
if (is.null(selector)) | ||
selector <- paste0("#", session$ns(id)) | ||
session$sendCustomMessage( | ||
type = "shinybusy-block-output", | ||
message = list( | ||
selector = selector, | ||
type = type, | ||
text = text, | ||
config = list(...) | ||
) | ||
) | ||
} | ||
|
||
#' @param timeout Unblock after a delay. | ||
#' @export | ||
#' | ||
#' @rdname block | ||
unblock <- function(id, | ||
selector = NULL, | ||
timeout = 0, | ||
session = shiny::getDefaultReactiveDomain()) { | ||
if (is.null(selector)) | ||
selector <- paste0("#", session$ns(id)) | ||
session$sendCustomMessage( | ||
type = "shinybusy-unblock-output", | ||
message = list( | ||
selector = selector, | ||
timeout = timeout | ||
) | ||
) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
library(shinybusy) | ||
library(shiny) | ||
|
||
ui <- fluidPage( | ||
|
||
tags$h3("Block Output"), | ||
|
||
|
||
fluidRow( | ||
column( | ||
width = 6, | ||
plotOutput(outputId = "plot1"), | ||
actionButton("block_manually", "Block / unblock") | ||
), | ||
column( | ||
width = 6, | ||
plotOutput(outputId = "plot2"), | ||
actionButton("block_reac", "Block when calculating in reactive()") | ||
) | ||
) | ||
|
||
) | ||
|
||
server <- function(input, output, session) { | ||
|
||
output$plot1 <- renderPlot({ | ||
barplot(table(floor(runif(100) * 6))) | ||
}) | ||
|
||
observeEvent(input$block_manually, { | ||
if (input$block_manually %% 2 == 1) { | ||
block(id = "plot1", type = "pulse", svgColor = "#5ea4d8") | ||
} else { | ||
unblock(id = "plot1") | ||
} | ||
}) | ||
|
||
data_r <- reactive({ | ||
input$block_reac | ||
block( | ||
id = "plot2", | ||
type = "circle", | ||
text = "Calculating, please wait...", | ||
messageColor = "#FFF", | ||
svgColor = "#FFF", | ||
backgroundColor = "#5ea4d8" | ||
) | ||
Sys.sleep(3) | ||
data <- data.frame(x = rnorm(50), y = rnorm(50)) | ||
unblock(id = "plot2", timeout = 300) | ||
return(data) | ||
}) | ||
|
||
output$plot2 <- renderPlot({ | ||
plot(data_r()) | ||
}) | ||
|
||
} | ||
|
||
if (interactive()) | ||
shinyApp(ui, server) | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import "shiny"; | ||
import { Block } from 'notiflix/build/notiflix-block-aio'; | ||
|
||
Shiny.addCustomMessageHandler("shinybusy-block-output", function(data) { | ||
if (data.hasOwnProperty("text")) { | ||
Block[data.type](data.selector, data.text, data.config); | ||
} else { | ||
Block[data.type](data.selector,data.config); | ||
} | ||
}); | ||
Shiny.addCustomMessageHandler("shinybusy-unblock-output", function(data) { | ||
Block.remove(data.selector, data.timeout); | ||
}); |