替换 observeEvent() 以恢复闪亮应用程序中的自动功能
Replace observeEvent() to restore automatic functionality in a shiny app
我有下面这个闪亮的应用程序,当我从 select第一个复选框组 'Current Selection(s):'。问题是我想摆脱 actionbutton
并使 selection 自动更新。我为此使用了 observeEvent()
,但我不确定如何替换它们以实现上述功能。
#app
library(shiny)
library(shinyWidgets)
server <- function(input, output,session) {
## Pickerbox Ticker Selection ----
output$str <- renderUI({
pickerInput(
inputId = "strategy",
label = HTML("<p><span style='color: black'>Select Strategies (Max of 8):</span></p>"),
width = "100%",
choices =c("VOO","VO", "VIOO","df","fg"),
selected = c("VOO","VO", "VIOO"),
multiple = TRUE
)
})
## Checkbox Inputs ----
#selected tickers
output$check_group_buttons <- renderUI({
prettyCheckboxGroup(
inputId = "checked_tickers",
selected = input$strategy[1:length(input$strategy)],
label = HTML("<p><span style='color: black'>Current Selection(s):</span></p>"),
choices = input$strategy[1:length(input$strategy)],
#direction = "vertical",
inline = TRUE,
icon = icon("check-square-o"),
status = "success",
outline = TRUE,
animation = "pulse"
)
})
#display tickers
output$check_group_buttons2 <- renderUI({
prettyCheckboxGroup(
inputId = "checked_tickers_to_chart",
label = HTML("<p><span style='color: black'>Display Tickers for Visuals:</span></p>"),
selected = input$strategy[1:length(input$strategy)],
choices = input$strategy[1:length(input$strategy)],
inline = TRUE,
icon = icon("check-square-o"),
status = "success",
outline = TRUE,
animation = "pulse"
)
})
## Display Tickers ----
observeEvent(input$update_tickers_for_picker,{
updatePrettyCheckboxGroup(session = session,
inputId = "checked_tickers_to_chart",
choices = input$strategy,
selected = input$strategy,
prettyOptions = list(
icon = icon("check-square-o"),
status = "success",
outline = TRUE,
animation = "jelly")
)
})
#Managed update of universe selections
updated_tickers_for_picker <- eventReactive(input$update_tickers_for_picker,{
input$checked_tickers
})
observeEvent(input$update_tickers_for_picker,{
updatePickerInput(session = session,
inputId = "strategy",
choices = c("VOO","VO", "VIOO","df","fg"),
selected = updated_tickers_for_picker()
)
})
}
ui <- fluidPage(
sidebarPanel(
uiOutput("str", width = 6),
uiOutput("check_group_buttons"),
actionButton(inputId = "update_tickers_for_picker",
label = "Update",icon = icon("play-circle"),
style="color: #fff; background-color: #198dc7; border-color: #222d32; border-radius: 70px"),
uiOutput("check_group_buttons2")
),
mainPanel(
))
shinyApp(ui = ui, server = server)
您正在寻找这样的东西吗?此示例取自 UpdateCheckboxGroupInput
.
上的闪亮帮助
目标的诀窍是使用 observe
作为您的反应环境来监视第一个复选框组。
将此放入您的服务器,接近尾声。
...
#Managed update of universe selections
observe({
updated_tickers_for_picker <- input$checked_tickers
if (is.null(updated_tickers_for_picker))
updated_tickers_for_picker <- character(0)
updatePrettyCheckboxGroup(session = session,
inputId = "checked_tickers_to_chart",
choices = updated_tickers_for_picker,
selected = updated_tickers_for_picker,
prettyOptions = list(
icon = icon("check-square-o"),
status = "success",
outline = TRUE,
animation = "jelly"),
inline= TRUE
)
})
...
我有下面这个闪亮的应用程序,当我从 select第一个复选框组 'Current Selection(s):'。问题是我想摆脱 actionbutton
并使 selection 自动更新。我为此使用了 observeEvent()
,但我不确定如何替换它们以实现上述功能。
#app
library(shiny)
library(shinyWidgets)
server <- function(input, output,session) {
## Pickerbox Ticker Selection ----
output$str <- renderUI({
pickerInput(
inputId = "strategy",
label = HTML("<p><span style='color: black'>Select Strategies (Max of 8):</span></p>"),
width = "100%",
choices =c("VOO","VO", "VIOO","df","fg"),
selected = c("VOO","VO", "VIOO"),
multiple = TRUE
)
})
## Checkbox Inputs ----
#selected tickers
output$check_group_buttons <- renderUI({
prettyCheckboxGroup(
inputId = "checked_tickers",
selected = input$strategy[1:length(input$strategy)],
label = HTML("<p><span style='color: black'>Current Selection(s):</span></p>"),
choices = input$strategy[1:length(input$strategy)],
#direction = "vertical",
inline = TRUE,
icon = icon("check-square-o"),
status = "success",
outline = TRUE,
animation = "pulse"
)
})
#display tickers
output$check_group_buttons2 <- renderUI({
prettyCheckboxGroup(
inputId = "checked_tickers_to_chart",
label = HTML("<p><span style='color: black'>Display Tickers for Visuals:</span></p>"),
selected = input$strategy[1:length(input$strategy)],
choices = input$strategy[1:length(input$strategy)],
inline = TRUE,
icon = icon("check-square-o"),
status = "success",
outline = TRUE,
animation = "pulse"
)
})
## Display Tickers ----
observeEvent(input$update_tickers_for_picker,{
updatePrettyCheckboxGroup(session = session,
inputId = "checked_tickers_to_chart",
choices = input$strategy,
selected = input$strategy,
prettyOptions = list(
icon = icon("check-square-o"),
status = "success",
outline = TRUE,
animation = "jelly")
)
})
#Managed update of universe selections
updated_tickers_for_picker <- eventReactive(input$update_tickers_for_picker,{
input$checked_tickers
})
observeEvent(input$update_tickers_for_picker,{
updatePickerInput(session = session,
inputId = "strategy",
choices = c("VOO","VO", "VIOO","df","fg"),
selected = updated_tickers_for_picker()
)
})
}
ui <- fluidPage(
sidebarPanel(
uiOutput("str", width = 6),
uiOutput("check_group_buttons"),
actionButton(inputId = "update_tickers_for_picker",
label = "Update",icon = icon("play-circle"),
style="color: #fff; background-color: #198dc7; border-color: #222d32; border-radius: 70px"),
uiOutput("check_group_buttons2")
),
mainPanel(
))
shinyApp(ui = ui, server = server)
您正在寻找这样的东西吗?此示例取自 UpdateCheckboxGroupInput
.
目标的诀窍是使用 observe
作为您的反应环境来监视第一个复选框组。
将此放入您的服务器,接近尾声。
...
#Managed update of universe selections
observe({
updated_tickers_for_picker <- input$checked_tickers
if (is.null(updated_tickers_for_picker))
updated_tickers_for_picker <- character(0)
updatePrettyCheckboxGroup(session = session,
inputId = "checked_tickers_to_chart",
choices = updated_tickers_for_picker,
selected = updated_tickers_for_picker,
prettyOptions = list(
icon = icon("check-square-o"),
status = "success",
outline = TRUE,
animation = "jelly"),
inline= TRUE
)
})
...