Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 基于搜索按钮过滤闪亮仪表板中的绘图图表_R_Shiny_Shinydashboard_Shinyapps_Shiny Reactivity - Fatal编程技术网

R 基于搜索按钮过滤闪亮仪表板中的绘图图表

R 基于搜索按钮过滤闪亮仪表板中的绘图图表,r,shiny,shinydashboard,shinyapps,shiny-reactivity,R,Shiny,Shinydashboard,Shinyapps,Shiny Reactivity,以下是可复制代码 # DF branch <- c("North", "South","South","North","North","South","North") cars <- c("Toyota","Nissan","BMW","Nissan","F

以下是可复制代码

# DF
branch <- c("North", "South","South","North","North","South","North")
cars <- c("Toyota","Nissan","BMW","Nissan","Ford","Toyota","Nissan")
insured <- c("Yes","Yes","No","Yes","Yes","Yes","No")
price <- c(21000, 23400, 26800,21000, 23400, 26800,21000)
salesDF <- data.frame(branch, cars,insured, price)
carBranch <- unique(salesDF$branch)



library(shiny)
library(DT)
library(shinydashboard)
library(plotly)
library(tidyverse)

# Define UI for application that draws a histogram
ui <- fluidPage(
  
  # Application title
  titlePanel("Car Sales"),
  
  # Sidebar with the selectInput Slider
  sidebarLayout(
    
    sidebarMenu(
      sidebarSearchForm(textId = "Search", buttonId = "search Car",
                        label = "Search Town")
    ),    
    
    # Show the DataTable
    mainPanel(
      box(title = "Car Sales", width = 7, height=NULL, solidHeader = T, status = "warning",
          plotlyOutput("carBranch"))
    )
  )
)

# Define server logic required to draw a histogram
server <- function(input, output) {
  
  output$carBranch <- renderPlotly({
    ggplot(salesDF, aes(branch, insured)) + 
      geom_bar(stat = "identity")
  })
  
}

# Run the application 
shinyApp(ui = ui, server = server)
#DF

branch也许你在找这个

 Define UI for application that draws a histogram
ui <- fluidPage(

  # Application title
  titlePanel("Car Sales"),

  # Sidebar with the selectInput Slider
  sidebarLayout(

    sidebarMenu(
      sidebarSearchForm(textId = "Search", buttonId = "search Car",
                        label = "Search Town"),
      selectInput("mycar", "Choose a Car" , choices=unique(salesDF$cars))
    ),

    # Show the DataTable
    mainPanel(
      box(title = "Car Sales w/ selectInput", width = 6, height=NULL, solidHeader = T, status = "warning",
          plotlyOutput("carBranch", width=400)),
      box(title = "Car Sales w/ SearchForm", width = 6, height=NULL, solidHeader = T, status = "success",
          plotlyOutput("carBranch2", width=400))
    )
  )
)

# Define server logic required to draw a histogram
server <- function(input, output) {

  output$carBranch <- renderPlotly({
    ggplot(salesDF[salesDF$cars %in% input$mycar,], aes(x=branch, y=price, fill=factor(insured))) +
      geom_bar(stat = "identity") + labs(fill="Insured)")
  })
  output$carBranch2 <- renderPlotly({
    req(input$Search)
    df <- salesDF
    df$ucars <- toupper(df$cars)
    if (sum(df$ucars %in% toupper(input$Search))>0) {
      ggplot(df[df$ucars %in% toupper(input$Search),], aes(x=branch, y=price, fill=factor(insured))) +
        geom_bar(stat = "identity") + labs(fill="Insured)")
    }else return(NULL)
  })
  
}

# Run the application
shinyApp(ui = ui, server = server)
为绘制直方图的应用程序定义UI

它能工作。小调整请求,您知道如何捕捉错误吗,例如,如果汽车模型不存在,它将返回一个文本,指示汽车不存在?另外,您知道如何使搜索不区分大小写吗?@Sayari,请尝试更新的代码。