我想放置一个搜索栏,用于在 Shiny 应用程序中查找某个单词的所有出现位置。我有这段代码可以与 boton_google 一起使用,所以我希望它可以与所有按钮一起使用。例如,如果我正在搜索“Abrir”,那么计数和标记的单词必须是两个。我认为问题出在函数
contextId
的 searchbar()
参数上。
library(shiny)
library(bs4Dash)
library(stringr)
library(rintrojs)
library(shinyjs)
library(shinyWidgets)
library(fresh)
library(shinyWidgets)
library(shinySearchbar)
caja_con_botones <- function(titulo, ..., botones) {
div(
h3(titulo, style = "color: steelblue;"),
div(
lapply(botones, function(boton) {
div(boton, style = "margin-bottom: 5px;")
})
),
style = "text-align:center; border: 1px solid steelblue; padding: 10px;"
)
}
# Función para crear botones
caja_elemento <- function(nombre, id, link, color) {
color_class <- switch(color,
"rojo" = "btn-danger",
"azul" = "btn-primary",
"verde" = "btn-success",
"primary") # Default to "primary" if color is not recognized
tags$button(
id = id,
class = paste("btn", color_class),
type = "button",
onclick = paste0("window.open('", link, "', '_blank');"),
nombre
)
}
# Crear botones
boton_google <- caja_elemento("Abrir Google", "boton_google", "https://www.google.com/", "azul")
boton_facebook <- caja_elemento("Abrir Facebook", "boton_facebook", "https://www.facebook.com/", "red")
# UI de la aplicación Shiny
ui <- fluidPage(
fluidRow(
searchbar("buscador", contextId = "boton_google")
),
fluidRow(
caja_con_botones("Mis Enlaces",
botones = list(boton_google, boton_facebook))
)
)
server <- function(input, output) {
}
shinyApp(ui, server)
当我有多个
contextId
时如何解决问题?