Como você pode ver no meu aplicativo abaixo, eu faço a filtragem, mas recebo Aviso: Erro na ordem: o argumento 1 não é um vetor ao tentar filtrar meus dados com o widget.
library(shiny)
library(shinydashboard)
library(dplyr)
library(plotly)
library(DT)
library(zoo)
library(shinyWidgets)
# Sample data
sample_data <- tibble::tibble(
keyword = c("closing costs", "competitive commission", "curb appeal", "expert negotiation",
"home inspection", "market analysis", "mortgage pre-approval", "open house",
"price reduction", "staging tips"),
gmb_id = rep("43763", 10),
date = seq.Date(from = as.Date("2025-03-10"), by = "1 day", length.out = 10),
pin_count = rep(39, 10),
gmb_return = runif(10, -0.05, 0.05),
gmb_abs_return = abs(runif(10, -0.05, 0.05))
)
ui <- dashboardPage(
dashboardHeader(title = "🔧 Toy Pin Volatility"),
dashboardSidebar(
sidebarMenu(
menuItem("Pin Volatility per Keyword", tabName = "pin_tab", icon = icon("map-pin")),
pickerInput(
inputId = "selected_keywords_pins",
label = "Select Keyword(s)",
choices = unique(sample_data$keyword),
selected = unique(sample_data$keyword)[1:3],
multiple = TRUE,
options = list(`actions-box` = TRUE)
)
)
),
dashboardBody(
tabItems(
tabItem(
tabName = "pin_tab",
fluidRow(
box(width = 12, DTOutput("volatility_table_pins"))
)
)
)
)
)
server <- function(input, output, session) {
rolling_pins <- reactive({
req(input$selected_keywords_pins)
sample_data %>%
filter(trimws(keyword) %in% trimws(input$selected_keywords_pins)) %>%
arrange(keyword, gmb_id, date) %>%
group_by(keyword, gmb_id) %>%
mutate(
rolling_volatility = zoo::rollapply(gmb_abs_return,
width = 3,
FUN = sd,
fill = NA,
align = "right")
) %>%
ungroup() %>%
na.omit()
})
output$volatility_table_pins <- renderDT({
datatable(
rolling_pins(),
options = list(pageLength = 10, scrollX = TRUE),
rownames = FALSE
)
})
}
shinyApp(ui, server)