相关输入的闪亮优先级
考虑使用三个输入的这个应用程序,所有这些应用程序彼此相关...
library(tidyverse)
library(shiny)
df <- mtcars %>%
split(.$vs)
ui <- fluidPage(
sidebarPanel(
radioButtons("no1", "Select", choices = names(df)),
selectInput("no2", "select", choices = NULL),
selectInput("no3", "select", choices = NULL)
),
mainPanel(plotOutput("plot"))
)
server <- function(input, output, session){
rv <- reactiveValues()
observe({
req(input$no1)
updateSelectInput(session,"no2", choices = df[[input$no1]]$cyl)
}, priority = 10)
observe({
rv$after_v1_v2 <- df[[input$no1]] %>% filter(cyl == input$no2)
}, priority = 9)
observe({
req(input$no1)
req(input$no2)
updateSelectInput(session,"no3", choices = rv$after_v1_v2$am )
}, priority = 8)
observe({
rv$after_v3 <- rv$after_v1_v2 %>% filter(am == input$no3)
}, priority = 7)
output$plot <- renderPlot({
Sys.sleep(2)
rv$after_v3 %>%
ggplot(aes(disp, hp)) +
geom_point()
})
outputOptions(output, "plot", priority = 1)
}
shiny::shinyApp(ui, server)
...我如何防止在更新侧面输入之前呈现图。如您所见,优先参数无效。更新应依次独立进行哪些输入更改,例如No1&gt;&gt; no2&gt;&gt; NO3,然后最后是情节。
我知道有一个debounce()
,但我不想“手动”放慢应用程序。
Consider this app with three inputs and all are related to each other...
library(tidyverse)
library(shiny)
df <- mtcars %>%
split(.$vs)
ui <- fluidPage(
sidebarPanel(
radioButtons("no1", "Select", choices = names(df)),
selectInput("no2", "select", choices = NULL),
selectInput("no3", "select", choices = NULL)
),
mainPanel(plotOutput("plot"))
)
server <- function(input, output, session){
rv <- reactiveValues()
observe({
req(input$no1)
updateSelectInput(session,"no2", choices = df[[input$no1]]$cyl)
}, priority = 10)
observe({
rv$after_v1_v2 <- df[[input$no1]] %>% filter(cyl == input$no2)
}, priority = 9)
observe({
req(input$no1)
req(input$no2)
updateSelectInput(session,"no3", choices = rv$after_v1_v2$am )
}, priority = 8)
observe({
rv$after_v3 <- rv$after_v1_v2 %>% filter(am == input$no3)
}, priority = 7)
output$plot <- renderPlot({
Sys.sleep(2)
rv$after_v3 %>%
ggplot(aes(disp, hp)) +
geom_point()
})
outputOptions(output, "plot", priority = 1)
}
shiny::shinyApp(ui, server)
...how I prevent that the plot is rendered before the sidepanel inputs are updated. As you can see the priority parameters have no effect. The update should take place sequentially independent which input is changed e.g. no1 >> no2 >> no3 and then finally the plot.
I know there is a debounce()
, but I don't want to "manually" slow down the app.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
FreezereActiveValue
找到了解决方案。Found a solution using
freezeReactiveValue
.