r - 在 plotly 图表中添加一个搜索栏,该搜索栏已被另一个闪亮的小部件子集化
问题描述
我有shiny
下面的应用程序,其中根据选择plotly
显示条形图。pickerInput()
我还想添加一个输入,例如我作为示例Search
提供的包中默认提供的输入。DT
用户将能够Country
在搜索栏中搜索特定内容,同时pickerInput()
仍会显示“所有国家/地区”。selectInput()
如果这是一个或其他什么,我没有问题,只是为了完成这项工作。
library(shiny)
library(plotly)
library(shinyWidgets)
library(DT)
Country<-c("EU","CHE","ITA")
Value<-c(3,2,1)
dat<-data.frame(Country,Value)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
pickerInput(
inputId = "p1",
label = "",
choices = dat$Country,
multiple = TRUE,
selected = dat$Country,
options = pickerOptions(`actions-box` = TRUE)
)
),
mainPanel(
textInput("search", "Search", ""),
plotlyOutput("line"),
DTOutput("dtline")
)
)
)
server <- function(input, output) {
output$line<-renderPlotly({
dat <- subset(dat, Country %in% input$p1|Country%in%search)
fig <- plot_ly(dat,
x = ~Country,
y = ~Value,
type = "bar"
)
fig
})
output$dtline<-renderDataTable({
dat <- subset(dat, Country %in% input$p1)
datatable(dat)
})
}
shinyApp(ui = ui, server = server)
解决方案
推荐阅读
- genexus - 报告问题 Genexus 16 试用版
- visual-studio-code - 从 Visual Studio Code 中的 grep(或 ack 或编译器或其他)打开结果作为搜索结果或问题?
- python - 使用正则表达式从 Twitter 数据中提取用户名
- python - 从响应 python 中获取值
- android - 我如何从我的 android 应用程序中共享什么应用程序语音笔记 (.opus) 文件?
- github - 使用 API 在源文件中搜索 Github 存储库
- google-apps-script - Google 表格变量不起作用,硬编码字符串起作用
- android - 手势检测器无法在 StackView 内触发
- python - 我可以在同一个脚本中构建三个 keras 模型吗?
- python - 在 cython 命名空间中编译时是否有完整的类型、函数列表?