diff --git a/news/index.html b/news/index.html index 2a9a399bb..a0fe3ff56 100644 --- a/news/index.html +++ b/news/index.html @@ -54,6 +54,7 @@
Small improvements to the default pulse busy indicator to better blend with any background. It’s also now slightly smaller by default. (#4122)
When spinners and the pulse busy indicators are enabled, Shiny now shows the pulse indicator when dynamic UI elements are recalculating if no other spinners are present in the app. (#4137)
Improve collection of deep stack traces (stack traces that are tracked across steps in an async promise chain) with coro async generators such as elmer chat streams. Previously, Shiny treated each iteration of an async generator as a distinct deep stack, leading to pathologically long stack traces; now, Shiny only keeps/prints unique deep stack trace, discarding duplicates. (#4156)
Added an example to the ExtendedTask documentation. (@daattali #4087)
Returns one of the following values:
"initial": This ExtendedTask has not yet been invoked
"running": An invocation is currently running
"success": An invocation completed successfully, and a value can be
-retrieved via the result() method
result() method
"error": An invocation completed with an error, which will be
-re-thrown if you call the result() method
result() method
result()result()Attempts to read the results of the most recent invocation. This is a reactive read that invalidates as the task's status changes.
The actual behavior differs greatly depending on the current status of
@@ -203,7 +203,7 @@ aware that if the result isn't ready for whatever reason, processing will
stop in much the same way as req(FALSE) does, but when the result is
ready you'll get invalidated, and when you run again the result should be
there.
Note that the result() method is generally not meant to be used with
+
Note that the result() method is generally not meant to be used with
observeEvent(), eventReactive(), bindEvent(), or isolate() as the
invalidation will be ignored.
if (FALSE) { # rlang::is_interactive() && rlang::is_installed("future")
+
+library(shiny)
+library(bslib)
+library(future)
+plan(multisession)
+
+ui <- page_fluid(
+ titlePanel("Extended Task Demo"),
+ p(
+ 'Click the button below to perform a "calculation"',
+ "that takes a while to perform."
+ ),
+ input_task_button("recalculate", "Recalculate"),
+ p(textOutput("result"))
+)
+
+server <- function(input, output) {
+ rand_task <- ExtendedTask$new(function() {
+ future(
+ {
+ # Slow operation goes here
+ Sys.sleep(2)
+ sample(1:100, 1)
+ },
+ seed = TRUE
+ )
+ })
+
+ # Make button state reflect task.
+ # If using R >=4.1, you can do this instead:
+ # rand_task <- ExtendedTask$new(...) |> bind_task_button("recalculate")
+ bind_task_button(rand_task, "recalculate")
+
+ observeEvent(input$recalculate, {
+ # Invoke the extended in an observer
+ rand_task$invoke()
+ })
+
+ output$result <- renderText({
+ # React to updated results when the task completes
+ number <- rand_task$result()
+ paste0("Your number is ", number, ".")
+ })
+}
+
+shinyApp(ui, server)
+}
+reactiveVal. See the Examples section for an illustration.
value <- reactiveVal(0) # rv <- reactiveValues(value = 0)
observeEvent(input$minus, {
- newValue <- value() - 1 # newValue <- rv$value - 1
- value(newValue) # rv$value <- newValue
+ newValue <- value() - 1 # newValue <- rv$value - 1
+ value(newValue) # rv$value <- newValue
})
observeEvent(input$plus, {
- newValue <- value() + 1 # newValue <- rv$value + 1
- value(newValue) # rv$value <- newValue
+ newValue <- value() + 1 # newValue <- rv$value + 1
+ value(newValue) # rv$value <- newValue
})
output$value <- renderText({
- value() # rv$value
+ value() # rv$value
})
}
diff --git a/reference/tabPanel.html b/reference/tabPanel.html
index df12bf69b..b5b2f2cac 100644
--- a/reference/tabPanel.html
+++ b/reference/tabPanel.html
@@ -110,25 +110,25 @@ This function should be used within tabsetPanel(type = "hidden"). S
)
#> <div class="col-sm-8" role="main">
#> <div class="tabbable">
-#> <ul class="nav nav-tabs" data-tabsetid="1018">
+#> <ul class="nav nav-tabs" data-tabsetid="7604">
#> <li class="active">
-#> <a href="#tab-1018-1" data-toggle="tab" data-bs-toggle="tab" data-value="Plot">Plot</a>
+#> <a href="#tab-7604-1" data-toggle="tab" data-bs-toggle="tab" data-value="Plot">Plot</a>
#> </li>
#> <li>
-#> <a href="#tab-1018-2" data-toggle="tab" data-bs-toggle="tab" data-value="Summary">Summary</a>
+#> <a href="#tab-7604-2" data-toggle="tab" data-bs-toggle="tab" data-value="Summary">Summary</a>
#> </li>
#> <li>
-#> <a href="#tab-1018-3" data-toggle="tab" data-bs-toggle="tab" data-value="Table">Table</a>
+#> <a href="#tab-7604-3" data-toggle="tab" data-bs-toggle="tab" data-value="Table">Table</a>
#> </li>
#> </ul>
-#> <div class="tab-content" data-tabsetid="1018">
-#> <div class="tab-pane active" data-value="Plot" id="tab-1018-1">
+#> <div class="tab-content" data-tabsetid="7604">
+#> <div class="tab-pane active" data-value="Plot" id="tab-7604-1">
#> <div class="shiny-plot-output html-fill-item" id="plot" style="width:100%;height:400px;"></div>
#> </div>
-#> <div class="tab-pane" data-value="Summary" id="tab-1018-2">
+#> <div class="tab-pane" data-value="Summary" id="tab-7604-2">
#> <pre class="shiny-text-output noplaceholder" id="summary"></pre>
#> </div>
-#> <div class="tab-pane" data-value="Table" id="tab-1018-3">
+#> <div class="tab-pane" data-value="Table" id="tab-7604-3">
#> <div id="table" class="shiny-html-output"></div>
#> </div>
#> </div>
diff --git a/reference/tabsetPanel.html b/reference/tabsetPanel.html
index f41a8abec..6f350fd81 100644
--- a/reference/tabsetPanel.html
+++ b/reference/tabsetPanel.html
@@ -135,25 +135,25 @@ tabPanels
)
#> <div class="col-sm-8" role="main">
#> <div class="tabbable">
-#> <ul class="nav nav-tabs" data-tabsetid="6423">
+#> <ul class="nav nav-tabs" data-tabsetid="5090">
#> <li class="active">
-#> <a href="#tab-6423-1" data-toggle="tab" data-bs-toggle="tab" data-value="Plot">Plot</a>
+#> <a href="#tab-5090-1" data-toggle="tab" data-bs-toggle="tab" data-value="Plot">Plot</a>
#> </li>
#> <li>
-#> <a href="#tab-6423-2" data-toggle="tab" data-bs-toggle="tab" data-value="Summary">Summary</a>
+#> <a href="#tab-5090-2" data-toggle="tab" data-bs-toggle="tab" data-value="Summary">Summary</a>
#> </li>
#> <li>
-#> <a href="#tab-6423-3" data-toggle="tab" data-bs-toggle="tab" data-value="Table">Table</a>
+#> <a href="#tab-5090-3" data-toggle="tab" data-bs-toggle="tab" data-value="Table">Table</a>
#> </li>
#> </ul>
-#> <div class="tab-content" data-tabsetid="6423">
-#> <div class="tab-pane active" data-value="Plot" id="tab-6423-1">
+#> <div class="tab-content" data-tabsetid="5090">
+#> <div class="tab-pane active" data-value="Plot" id="tab-5090-1">
#> <div class="shiny-plot-output html-fill-item" id="plot" style="width:100%;height:400px;"></div>
#> </div>
-#> <div class="tab-pane" data-value="Summary" id="tab-6423-2">
+#> <div class="tab-pane" data-value="Summary" id="tab-5090-2">
#> <pre class="shiny-text-output noplaceholder" id="summary"></pre>
#> </div>
-#> <div class="tab-pane" data-value="Table" id="tab-6423-3">
+#> <div class="tab-pane" data-value="Table" id="tab-5090-3">
#> <div id="table" class="shiny-html-output"></div>
#> </div>
#> </div>