Brilliant filter applied to two outputs

I am trying to create a toolbar in brilliant form with two visualizations (datatable and bargraph) that allow the user to apply the same filters to both visualizations simultaneously. I tried to use the solution presented here , but I think I missed something. "Data5" is the name of the data multiplier used to fill. Any help would be appreciated.

server.R

library(shiny)
library(ggplot2)
library(dplyr)

dt <- data5

shinyServer(function(input, output) {


data <- reactive({data5
    if (input$year != "All"){
      data <- data[data5$year == input$year,]
    }
   if (input$month != "All"){
      data <- data[data5$month == input$month,]
    }
   if (input$partner_name != "All"){
      data <- data[data5$partner_name == input$partner_name,]
    }
    if (input$cube_title != "All"){
      data <- data[data5$cube_title == input$cube_title,]
    }

  })

  #plots
  output$table1 <- renderDataTable({
    data
  })

  output$plot1 <- renderPlot({
    ggplot(data=subset(data5,cube_title=="Leads"), aes(x=month,y=f0_)) + geom_bar(fill="blue", stat = "identity") + ylab("Leads") + ggtitle("Leads")
  })
  output$plot2 <- renderPlot({
    ggplot(data=subset(data5,cube_title==c("CommunityProfileViews","HomeProfileViews")), aes(x=month,y=f0_)) + geom_bar(fill="blue", stat = "identity") + ylab("Profile Views") + ggtitle("Profile Views")

  })

})

ui.R

dashboardPage(
  skin = "blue",
  dashboardHeader(title = "Basic dashboard"),
  dashboardSidebar(
     ( 
          selectInput("year", 
                      "Year:", 
                      c("All", 
                        unique(as.character(data5$year))))
      ),
      ( 
          selectInput("month", 
                      "Month:", 
                      c("All", 
                        unique(as.character(data5$month))))
      ),
      (
          selectInput("partner_name", 
                      "Partner:", 
                      c("All", 
                        unique(as.character(data5$partner_name))))
                        ),
      (
          selectInput("cube_title", 
                      "Metric:", 
                      c("All", 
                        unique(as.character(data5$cube_title))))
      )        
    ),

  dashboardBody(


     tabsetPanel(id = "tabSelected",
                tabPanel("Charts", plotOutput("plot1"), 
                box(plotOutput("plot2"))),
                tabPanel("DataTable", dataTableOutput("table1"))
    )

               )
            )
+4
source share
1 answer

Reaction 1: returns a function, not an object. Therefore, we need to call data(), not datain yours renderDataTableand renderPlotfunctions

2: data() . data5, :

output$plot1 <- renderPlot({
    Temp <- data()
    ggplot(data=subset(Temp,cube_title=="Leads"), aes(x=month,y=f0_)) + geom_bar(fill="blue", stat = "identity") + ylab("Leads") + ggtitle("Leads")
}) 

3:. . :

data <- reactive({ #The data5 that was here is not necessary
  temp <- data5 
  if (input$year != "All"){
    temp <- temp[temp$year == input$year,]
  }
  if (input$month != "All"){
    temp <- temp[temp$month == input$month,]
  }
  if (input$partner_name != "All"){
    temp <- temp[temp$partner_name == input$partner_name,]
  }
  if (input$cube_title != "All"){
    temp <- temp[temp$cube_title == input$cube_title,]
  }
  return(temp)

})

, data(), data.frame

4: ( ) data . - . DT - . , , exists("NameToCheck") .

+4

Source: https://habr.com/ru/post/1620460/


All Articles