首页 > 解决方案 > 在 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)
    

标签: rshinyplotly

解决方案


推荐阅读