我正在开发一个Shiny应用程序以过滤数据库(例如Excel),并且我想在“下拉按钮”打开时停止该应用程序的所有计算。你知道我该怎么做吗?这是我的第一个Shiny应用程序,因此我很确定自己犯了一些愚蠢的错误。
在我的下拉按钮中,我有一个CheckBoxGroupInput,为数据库的一个变量选择了不同的选项。问题:我必须在CheckBoxGroupInput内部的每个选择之间等待几秒钟,因为应用程序正在为CheckBox中的每个其他选择刷新。
一个变量的示例:
用户界面:
MV
SUNMI
선미
누아르
Noir
服务器:
用于刷新不同CheckBox中的每个列表的功能:
dropdownButton(
label = "Country :", status = "default", width = 200, circle = FALSE,
actionButton(inputId = "country_all", label = "(Un)select all"),
uiOutput("countrybis")
),
verbatimTextOutput(outputId = "country_print")
“国家/地区”列的计算:
Function_List_Data <- function(p_type, p_processchoice, p_year, p_variable, p_product, p_country,
p_item, p_season, p_region, p_calcamp){
if(p_processchoice == "GROSSVAR"){
data <- dataset_var[YEARBIS >= p_year[1] & YEARBIS <= p_year[2],]}
else if(p_processchoice == "YIELD"){
data <- dataset_rdt[YEARBIS >= p_year[1] & YEARBIS <= p_year[2],]}
else{data <- dataset[YEARBIS >= p_year[1] & YEARBIS <= p_year[2],]}
if (p_region == 2) {data <- data[REGION %in% list("EU-15","EU-27","EU-28")]}
else if (p_region == 3) {data <- data[REGION %in% list("C.I.S.")]}
if (p_calcamp == 2) {data <- data[`CAMPAIGN/CALENDAR` == "CAMPAIGN",]}
else if (p_calcamp == 3) {data <- data[`CAMPAIGN/CALENDAR` == "CALENDAR",]}
else if (p_calcamp == 4) {data <- data[`CAMPAIGN/CALENDAR` == "OTHERS",]}
if (!is.null(p_variable)) {data <- data[VARIABLE %in% p_variable]}
if (!is.null(p_product)) {data <- data[PRODUCT %in% p_product,]}
if (!is.null(p_country)) {data <- data[COUNTRY %in% p_country,]}
if (!is.null(p_item)) {data <- data[ITEM %in% p_item,]}
if (!is.null(p_season)) {data <- data[SEASON %in% p_season,]}
if(nrow(data)<1){ data <- data[1,] }
if (p_type == "VARIABLE"){List <- unique(unlist(data$VARIABLE), use.names = FALSE)}
else if (p_type == "PRODUCT"){List <- unique(unlist(data$PRODUCT), use.names = FALSE)}
else if (p_type == "COUNTRY"){List <- unique(unlist(data$COUNTRY), use.names = FALSE)}
else if (p_type == "ITEM"){List <- unique(unlist(data$ITEM), use.names = FALSE)}
else if (p_type == "SEASON"){List <- unique(unlist(data$SEASON), use.names = FALSE)}
return(List)
}
编辑: 当我仅在单击DropdownButton时计算Country_List时,它不起作用,您可以在屏幕上看到错误:
Error received : the Country_List is calculate after the CheckBox is print
按钮全选/全选:
Country_List <- reactive({
Function_List_Data(p_type = "COUNTRY",
p_processchoice = input$dataprocess_choice,
p_year = input$year,
p_variable = input$variable_list,
p_product = input$product_list,
p_country = NULL,
p_item = input$item_list,
p_season = input$season_list,
p_region = input$region,
p_calcamp = input$campaign_calendar)})
observeEvent(input$country_all, {
if (is.null(input$country_list)) {
updateCheckboxGroupInput(session = session, inputId = "country_list", selected = Country_List())}
else {updateCheckboxGroupInput(session = session, inputId = "country_list", selected = "")}
})
output$country_print <- renderPrint({
if(is.null(input$country_list)){"- ALL -"}
else{as.matrix(input$country_list)}
})
output$countrybis <- renderUI({
checkboxGroupInput(inputId = "country_list", label = "Choose", choices = sort(Country_List()), selected = input$country_list)
})
RenderPrint:
observeEvent(input$country_all, {
Country_List <- Function_List_Data(p_type = "COUNTRY",
p_processchoice = input$dataprocess_choice,
p_year = input$year,
p_variable = input$variable_list,
p_product = input$product_list,
p_country = NULL,
p_item = input$item_list,
p_season = input$season_list,
p_region = input$region,
p_calcamp = input$campaign_calendar)
if (is.null(input$country_list)) {
updateCheckboxGroupInput(session = session, inputId = "country_list", selected = Country_List)}
else {updateCheckboxGroupInput(session = session, inputId = "country_list", selected = "")}})
复选框:
output$country_print <- renderPrint({
if(is.null(input$country_list)){"- ALL -"}
else{as.matrix(input$country_list)}})