filterting data table not working

data table filter is working fine with this syntax

     total %>%
       filter(
        CustomerName %in% CustomerName(),
         as.Date(Order_Date) %in% as.Date(Order_Date())
       )

but when I add this it's not filtering the data but displaying the entire data table which is obvious in absence of filterring data.

DT::datatable(extensions = 'Buttons',total[,],options = list(dom = 'Blfrtip',
    buttons =
      list('copy', 'print', list(
        extend = 'collection',
        buttons = c('csv', 'excel', 'pdf'),
        text = 'Download'
      )),initComplete = JS(
    "function(settings, json) {",
    "$(this.api().table().header()).css({'background-color': '#090057', 'color': '#fff'});",
    "}"),lengthMenu = c(5,10,15,20), pageLength = 10,scrollX = TRUE),class = "nowrap cell-border hover stripe",editable = FALSE) 
  })

but when i try to add filter to this syntax it throws error.I know ,It's syntax error somewhere but I am unable to track what it is so please guide me through this error.

DT::datatable(extensions = 'Buttons',total[,],options = list(dom = 'Blfrtip',
    buttons =
      list('copy', 'print', list(
        extend = 'collection',
        buttons = c('csv', 'excel', 'pdf'),
        text = 'Download'
      )),initComplete = JS(
    "function(settings, json) {",
    "$(this.api().table().header()).css({'background-color': '#090057', 'color': '#fff'});",
    "}"),lengthMenu = c(5,10,15,20), pageLength = 10,scrollX = TRUE),class = "nowrap cell-border hover stripe",editable = FALSE) %>%
 filter(
        CustomerName %in% CustomerName(),
         as.Date(Order_Date) %in% as.Date(Order_Date())
       )
library(shiny)
library(plotly)
library(dplyr)
library(readr)
library(shinydashboard)
library(shinythemes)
library(dashboardthemes)

#total<-read.csv("C:/Users/dell/Downloads/archive (4)/List of Orders.csv")
total<-tibble::tribble(
         ~Order.ID,  ~Order_Date,              ~State,                ~City, ~CustomerName, ~sales,
         "B-25601",   "1/4/2018",           "Gujarat",          "Ahmedabad",      "Bharat",  1275L,
         "B-25602",   "1/4/2018",       "Maharashtra",               "Pune",       "Pearl",    66L,
         "B-25603",   "3/4/2018",    "Madhya Pradesh",             "Bhopal",       "Jahan",     8L,
         "B-25604",   "3/4/2018",         "Rajasthan",             "Jaipur",      "Divsha",    80L,
         "B-25605",   "5/4/2018",       "West Bengal",            "Kolkata",     "Kasheen",   168L,
         "B-25606",   "6/4/2018",         "Karnataka",          "Bangalore",       "Hazel",   424L,
         "B-25607",   "6/4/2018", "Jammu and Kashmir",            "Kashmir",    "Sonakshi",  2617L,
         "B-25608",   "8/4/2018",        "Tamil Nadu",            "Chennai",     "Aarushi",   561L,
         "B-25609",   "9/4/2018",     "Uttar Pradesh",            "Lucknow",      "Jitesh",   119L,
         "B-25610",   "9/4/2018",             "Bihar",              "Patna",      "Yogesh",  1355L,
         "B-25611",  "11/4/2018",            "Kerala", "Thiruvananthapuram",       "Anita",    24L,
         "B-25612",  "12/4/2018",            "Punjab",         "Chandigarh",   "Shrichand",   193L,
         "B-25613",  "12/4/2018",           "Haryana",         "Chandigarh",      "Mukesh",   180L,
         "B-25614", "13-04-2018",  "Himachal Pradesh",              "Simla",     "Vandana",   116L,
         "B-25615", "15-04-2018",            "Sikkim",            "Gangtok",      "Bhavna",   107L,
         "B-25616", "15-04-2018",               "Goa",                "Goa",       "Kanak",    12L,
         "B-25617", "17-04-2018",          "Nagaland",             "Kohima",       "Sagar",    38L,
         "B-25618", "18-04-2018",    "Andhra Pradesh",          "Hyderabad",       "Manju",    65L,
         "B-25619", "18-04-2018",           "Gujarat",          "Ahmedabad",      "Ramesh",   157L,
         "B-25620", "20-04-2018",       "Maharashtra",               "Pune",      "Sarita",    75L,
         "B-25621", "20-04-2018",    "Madhya Pradesh",             "Bhopal",      "Deepak",    87L,
         "B-25622", "22-04-2018",         "Rajasthan",             "Jaipur",     "Monisha",    50L,
         "B-25623", "22-04-2018",       "West Bengal",            "Kolkata",      "Atharv",  1364L,
         "B-25624", "22-04-2018",         "Karnataka",          "Bangalore",        "Vini",   476L,
         "B-25625", "23-04-2018", "Jammu and Kashmir",            "Kashmir",       "Pinky",   257L,
         "B-25626", "23-04-2018",       "Maharashtra",             "Mumbai",      "Bhishm",   856L,
         "B-25627", "23-04-2018",    "Madhya Pradesh",             "Indore",      "Hitika",   485L,
         "B-25628", "24-04-2018",             "Bihar",              "Patna",       "Pooja",    25L,
         "B-25629", "24-04-2018",            "Kerala", "Thiruvananthapuram",      "Hemant",  1076L,
         "B-25630", "24-04-2018",            "Punjab",         "Chandigarh",       "Sahil",   107L,
         "B-25631", "24-04-2018",           "Haryana",         "Chandigarh",        "Ritu",    68L,
         "B-25632", "25-04-2018",  "Himachal Pradesh",              "Simla",      "Manish",   781L,
         "B-25633", "26-04-2018",            "Sikkim",            "Gangtok",        "Amit",    43L,
         "B-25634", "26-04-2018",               "Goa",                "Goa",      "Sanjay",    30L,
         "B-25635", "26-04-2018",          "Nagaland",             "Kohima",       "Nidhi",   160L,
         "B-25636", "26-04-2018",       "Maharashtra",             "Mumbai",       "Nishi",   259L,
         "B-25637", "26-04-2018",    "Madhya Pradesh",             "Indore",       "Ashmi",  1603L,
         "B-25638", "26-04-2018",       "Maharashtra",               "Pune",       "Parth",   494L,
         "B-25639", "27-04-2018",    "Madhya Pradesh",             "Bhopal",       "Lisha",    98L,
         "B-25640", "27-04-2018",         "Rajasthan",             "Jaipur",     "Paridhi",    68L,
         "B-25641", "27-04-2018",       "West Bengal",            "Kolkata",     "Parishi",    42L,
         "B-25642", "28-04-2018",         "Karnataka",          "Bangalore",        "Ajay",   116L,
         "B-25643", "29-04-2018", "Jammu and Kashmir",            "Kashmir",       "Kirti",    22L,
         "B-25644", "30-04-2018",       "Maharashtra",             "Mumbai",      "Mayank",    14L,
         "B-25645",   "1/5/2018",    "Madhya Pradesh",             "Indore",      "Yaanvi",   305L,
         "B-25646",   "1/5/2018",             "Bihar",              "Patna",       "Sonal",   362L,
         "B-25647",   "3/5/2018",            "Kerala", "Thiruvananthapuram",      "Sharda",    12L,
         "B-25648",   "4/5/2018",            "Punjab",         "Chandigarh",      "Aditya",   353L,
         "B-25649",   "5/5/2018",           "Haryana",         "Chandigarh",      "Rachna",   193L,
         "B-25650",   "6/5/2018",       "Maharashtra",             "Mumbai",      "Chirag",   233L,
         "B-25651",   "7/5/2018",    "Madhya Pradesh",             "Indore",      "Anurag",   228L,
         "B-25652",   "8/5/2018",               "Goa",                "Goa",     "Tushina",   333L,
         "B-25653",   "8/5/2018",          "Nagaland",             "Kohima",       "Farah",   534L,
         "B-25654",  "10/5/2018",       "Maharashtra",             "Mumbai",       "Sabah",    53L,
         "B-25655",  "11/5/2018",    "Madhya Pradesh",             "Indore",        "Nida",   158L,
         "B-25656",  "11/5/2018",       "Maharashtra",               "Pune",    "Priyanka",   149L,
         "B-25657", "13-05-2018",    "Madhya Pradesh",             "Bhopal",      "Tulika",   105L,
         "B-25658", "14-05-2018",         "Rajasthan",             "Jaipur",     "Shefali",    26L,
         "B-25659", "15-05-2018",       "West Bengal",            "Kolkata",   "Sanskriti",    97L,
         "B-25660", "16-05-2018",         "Karnataka",          "Bangalore",      "Shruti",    59L,
         "B-25661", "17-05-2018", "Jammu and Kashmir",            "Kashmir",  "Subhashree",   635L,
         "B-25662", "17-05-2018",       "Maharashtra",             "Mumbai",       "Sweta",    46L,
         "B-25663", "19-05-2018",    "Madhya Pradesh",             "Indore",  "Pournamasi",  1103L,
         "B-25664", "20-05-2018",             "Bihar",              "Patna", "Pratyusmita",    55L,
         "B-25665", "21-05-2018",            "Kerala", "Thiruvananthapuram",   "Chayanika",    45L,
         "B-25666", "22-05-2018",            "Punjab",         "Chandigarh",       "Tanvi",    24L,
         "B-25667", "23-05-2018",           "Haryana",         "Chandigarh",      "Anjali",    35L,
         "B-25668", "24-05-2018",  "Himachal Pradesh",              "Simla",        "Rhea",  1560L,
         "B-25669", "25-05-2018",            "Sikkim",            "Gangtok",      "Piyali",   133L,
         "B-25670", "25-05-2018",               "Goa",                "Goa",     "Charika",   114L,
         "B-25671", "27-05-2018",          "Nagaland",             "Kohima",      "Mitali",   143L,
         "B-25672", "28-05-2018",    "Andhra Pradesh",          "Hyderabad",    "Akanksha",    40L,
         "B-25673", "28-05-2018",           "Gujarat",          "Ahmedabad",     "Arsheen",    34L,
         "B-25674", "28-05-2018",       "Maharashtra",               "Pune",      "Mahima",    42L,
         "B-25675", "31-05-2018",    "Madhya Pradesh",             "Bhopal",      "Shreya",    89L,
         "B-25676",   "1/6/2018",         "Rajasthan",             "Jaipur",     "Chandni",    19L,
         "B-25677",   "2/6/2018",       "West Bengal",            "Kolkata",        "Ekta",   249L,
         "B-25678",   "3/6/2018",         "Karnataka",          "Bangalore",     "Bathina",   711L,
         "B-25679",   "4/6/2018",       "Maharashtra",             "Mumbai",        "Avni",   496L,
         "B-25680",   "4/6/2018",    "Madhya Pradesh",             "Indore",     "Aayushi",   389L,
         "B-25681",   "4/6/2018",    "Madhya Pradesh",             "Indore",      "Bhawna",    40L,
         "B-25682",   "7/6/2018",             "Bihar",              "Patna",     "Krutika",    23L,
         "B-25683",   "8/6/2018",            "Kerala", "Thiruvananthapuram",      "Shreya",   382L,
         "B-25684",   "9/6/2018",       "Maharashtra",             "Mumbai",    "Samiksha",   637L,
         "B-25685",  "10/6/2018",    "Madhya Pradesh",             "Indore",     "Sheetal",   117L,
         "B-25686",  "11/6/2018",  "Himachal Pradesh",              "Simla",       "Pooja",   182L,
         "B-25687",  "11/6/2018",       "Maharashtra",             "Mumbai",      "Sanjna",   880L,
         "B-25688",  "11/6/2018",    "Madhya Pradesh",             "Indore",      "Swetha",   154L,
         "B-25689", "14-06-2018",       "Maharashtra",             "Mumbai", "Bhaggyasree",   816L,
         "B-25690", "15-06-2018",    "Madhya Pradesh",             "Indore",      "Gunjan",  1629L,
         "B-25691", "16-06-2018",       "Maharashtra",             "Mumbai",     "Akancha",    68L,
         "B-25692", "17-06-2018",    "Madhya Pradesh",             "Indore",      "Rashmi",   314L,
         "B-25693", "18-06-2018",    "Madhya Pradesh",             "Bhopal",       "Parna",   122L,
         "B-25694", "18-06-2018",         "Rajasthan",             "Jaipur",  "Subhasmita",    22L,
         "B-25695", "18-06-2018",       "West Bengal",            "Kolkata",      "Suhani",   434L,
         "B-25696", "21-06-2018",         "Karnataka",          "Bangalore",      "Noopur",  1061L,
         "B-25697", "22-06-2018", "Jammu and Kashmir",            "Kashmir",       "Vijay",    50L,
         "B-25698", "23-06-2018",        "Tamil Nadu",            "Chennai",      "Amisha",    37L,
         "B-25699", "24-06-2018",     "Uttar Pradesh",            "Lucknow",     "Kritika",   263L,
         "B-25700", "25-06-2018",       "Maharashtra",             "Mumbai",      "Shubhi",    36L,
         "B-25701", "26-06-2018",    "Madhya Pradesh",             "Indore",   "Maithilee",    76L,
         "B-25702", "27-06-2018",       "Maharashtra",             "Mumbai",      "Shaily",   273L,
         "B-25703", "28-06-2018",    "Madhya Pradesh",             "Indore",        "Ekta",    86L,
         "B-25704", "29-06-2018",       "Maharashtra",             "Mumbai",        "Riya",   133L,
         "B-25705", "30-06-2018",    "Madhya Pradesh",             "Indore",      "Shweta",   183L,
         "B-25706",   "1/7/2018",               "Goa",                "Goa",    "Swetlana",    20L,
         "B-25707",   "1/7/2018",       "Maharashtra",             "Mumbai",     "Shivani",    42L,
         "B-25708",   "1/7/2018",    "Madhya Pradesh",             "Indore",     "Kishwar",   100L,
         "B-25709",   "1/7/2018",    "Madhya Pradesh",             "Indore",   "Aakanksha",    30L,
         "B-25710",   "5/7/2018",       "Maharashtra",               "Pune",       "Megha",    55L,
         "B-25711",   "6/7/2018",    "Madhya Pradesh",             "Bhopal",      "Sakshi",   130L,
         "B-25712",   "7/7/2018",         "Rajasthan",             "Jaipur",    "Adhvaita",    27L,
         "B-25713",   "8/7/2018",       "West Bengal",            "Kolkata",      "Raksha",   245L,
         "B-25714",   "9/7/2018",         "Karnataka",          "Bangalore",       "Stuti",   211L,
         "B-25715",  "10/7/2018", "Jammu and Kashmir",            "Kashmir",     "Srishti",    31L,
         "B-25716",  "11/7/2018",        "Tamil Nadu",            "Chennai",     "Surabhi",    28L,
         "B-25717",  "12/7/2018",     "Uttar Pradesh",            "Lucknow",     "Manshul",   512L,
         "B-25718",  "12/7/2018",       "Maharashtra",             "Mumbai",      "Anjali",   925L,
         "B-25719",  "12/7/2018",    "Madhya Pradesh",             "Indore",      "Rashmi",   238L,
         "B-25720", "15-07-2018",            "Punjab",         "Chandigarh",     "Namrata",   351L,
         "B-25721", "16-07-2018",           "Haryana",         "Chandigarh",      "Anchal",   269L,
         "B-25722", "17-07-2018",  "Himachal Pradesh",              "Simla",  "Inderpreet",   200L,
         "B-25723", "18-07-2018",       "Maharashtra",             "Mumbai",        "Wale",    44L,
         "B-25724", "19-07-2018",    "Madhya Pradesh",             "Indore",     "Sheetal",     7L,
         "B-25725", "20-07-2018",          "Nagaland",             "Kohima",      "Anisha",    11L,
         "B-25726", "21-07-2018",       "Maharashtra",             "Mumbai",       "Kiran",    16L,
         "B-25727", "22-07-2018",    "Madhya Pradesh",             "Indore",   "Turumella",   172L,
         "B-25728", "22-07-2018",       "Maharashtra",               "Pune",     "Ameesha",    49L,
         "B-25729", "22-07-2018",    "Madhya Pradesh",             "Bhopal",   "Madhulika",   823L,
         "B-25730", "22-07-2018",         "Rajasthan",             "Jaipur",     "Rishabh",    23L,
         "B-25731", "26-07-2018",       "West Bengal",            "Kolkata",       "Akash",   457L,
         "B-25732", "27-07-2018",         "Karnataka",          "Bangalore",     "Anubhaw",    24L,
         "B-25733", "28-07-2018",       "Maharashtra",             "Mumbai",  "Dhirajendu",    25L,
         "B-25734", "29-07-2018",    "Madhya Pradesh",             "Indore",      "Pranav",   174L,
         "B-25735", "30-07-2018",     "Uttar Pradesh",            "Lucknow",     "Arindam",   206L,
         "B-25736", "31-07-2018",       "Maharashtra",             "Mumbai",      "Akshat",    21L,
         "B-25737",   "1/8/2018",    "Madhya Pradesh",             "Indore",     "Shubham",    34L,
         "B-25738",   "2/8/2018",            "Punjab",         "Chandigarh",       "Ayush",     9L,
         "B-25739",   "3/8/2018",           "Haryana",         "Chandigarh",       "Daksh",  1279L,
         "B-25740",   "3/8/2018",       "Maharashtra",             "Mumbai",        "Rane",    28L,
         "B-25741",   "3/8/2018",    "Madhya Pradesh",             "Indore",     "Navdeep",   427L,
         "B-25742",   "3/8/2018",               "Goa",                "Goa",      "Ashwin",   168L,
         "B-25743",   "7/8/2018",          "Nagaland",             "Kohima",        "Aman",  1327L,
         "B-25744",   "8/8/2018",    "Andhra Pradesh",          "Hyderabad",    "Devendra",   195L,
         "B-25745",   "9/8/2018",           "Gujarat",          "Ahmedabad",      "Kartik",   115L,
         "B-25746",  "10/8/2018",       "Maharashtra",               "Pune",      "Shivam",   668L,
         "B-25747",  "11/8/2018",    "Madhya Pradesh",             "Bhopal",       "Harsh",   227L,
         "B-25748",  "12/8/2018",         "Rajasthan",             "Jaipur",      "Nitant",    34L,
         "B-25749", "13-08-2018",       "Maharashtra",             "Mumbai",       "Ayush",   229L,
         "B-25750", "14-08-2018",    "Madhya Pradesh",             "Indore",   "Priyanshu",    54L,
         "B-25751", "14-08-2018",       "Maharashtra",             "Mumbai",     "Nishant",   269L,
         "B-25752", "14-08-2018",    "Madhya Pradesh",             "Indore",     "Vaibhav",   122L,
         "B-25753", "17-08-2018",     "Uttar Pradesh",            "Lucknow",      "Shivam",   105L,
         "B-25754", "18-08-2018",             "Bihar",              "Patna",      "Akshay",   450L,
         "B-25755", "19-08-2018",            "Kerala", "Thiruvananthapuram",     "Shourya",   121L,
         "B-25756", "20-08-2018",       "Maharashtra",             "Mumbai",       "Mohan",    44L,
         "B-25757", "21-08-2018",    "Madhya Pradesh",             "Indore",       "Mohit",     7L,
         "B-25758", "22-08-2018",  "Himachal Pradesh",              "Simla",     "Shubham",   396L,
         "B-25759", "23-08-2018",            "Sikkim",            "Gangtok",      "Soumya",    97L,
         "B-25760", "24-08-2018",               "Goa",                "Goa",       "Pooja",   110L,
         "B-25761", "25-08-2018",       "Maharashtra",             "Mumbai",     "Surabhi",   312L,
         "B-25762", "26-08-2018",    "Madhya Pradesh",             "Indore",     "Anudeep",     9L
         )

 
  

ui <- dashboardPage(
  dashboardHeader(title="dashboard"),
  dashboardSidebar(
    sidebarMenu(
    dateRangeInput(inputId = "date",
                 strong("Date Range"),
                start = '2012-06-16',
                 end = '2019-12-31',
                min = '2010-01-01',
                max = '2019-12-31',
                 separator = "TO"))),
  dashboardBody(
    shinyDashboardThemes(
      theme = "blue_gradient"
    ),
  fluidPage(
  plotlyOutput("state", height = 200),
  plotlyOutput("city", height = 200),
  plotlyOutput("customer", height = 200),
  plotlyOutput("sales", height = 300),
  dataTableOutput("datatable"))))

axis_titles <- . %>%
  layout(
    xaxis = list(title = ""),
    yaxis = list(title = "Sales"))

server <- function(input, output, session) {
  
  State <- reactiveVal()
  City <- reactiveVal()
  CustomerName<- reactiveVal()
  Order_Date <- reactiveVal()
  
  observeEvent(event_data("plotly_click", source = "State"), {
    State(event_data("plotly_click", source = "State")$x)
    City(NULL)
    Order_Date(NULL)
  })
  
 observeEvent(event_data("plotly_click", source = "City"), {
    City(event_data("plotly_click", source = "City")$x)
    CustomerName(NULL)
    Order_Date(NULL)
  })
 
  observeEvent(event_data("plotly_click", source = "CustomerName"), {
    CustomerName(event_data("plotly_click", source = "CustomerName")$x)
    Order_Date(NULL)
  })
  
  observeEvent(event_data("plotly_click", source = "Order_Date"), {
    Order_Date(event_data("plotly_click", source = "Order_Date")$x)
  })
  
  output$state <- renderPlotly({
     total%>%
      count(State, wt = sales) %>%
      plot_ly(x = ~State, y = ~n, source = "State") %>%
      axis_titles() %>% 
      layout(title = "State")
  })
  
   output$city <- renderPlotly({
    if (is.null(State())) return(NULL)
    total%>%
      filter( State %in% State()) %>%
      count(City, wt = sales) %>%
      plot_ly(x = ~City, y = ~n, source = "City") %>%
      axis_titles() %>%
      layout(title = State())
  })
 
  
  output$customer <- renderPlotly({
    if (is.null(City())) return(NULL)
    total%>%
      filter(City %in% City()) %>%
      count(CustomerName, wt = sales) %>%
      plot_ly(x = ~CustomerName, y = ~n, source = "CustomerName") %>%
      axis_titles() %>%
      layout(title = City())
  })
  
  output$sales <- renderPlotly({
    if (is.null(CustomerName())) return(NULL)
    
    total %>%
      filter(CustomerName %in% CustomerName()) %>%
      count(Order_Date, wt = sales) %>%
      plot_ly(x = ~Order_Date, y = ~n, source = "Order_Date") %>%
      add_lines() %>%
      axis_titles() %>%
      layout(title = paste(CustomerName(), "sales over time"))
  })
  
  output$datatable <- renderDataTable({
    if (is.null(Order_Date())) return(NULL)
    
    # total %>%
    #   filter(
    #     CustomerName %in% CustomerName(),
    #     as.Date(Order_Date) %in% as.Date(Order_Date())
    #   )
    DT::datatable(extensions = 'Buttons',total[,],options = list(dom = 'Blfrtip',
    buttons =
      list('copy', 'print', list(
        extend = 'collection',
        buttons = c('csv', 'excel', 'pdf'),
        text = 'Download'
      )),initComplete = JS(
    "function(settings, json) {",
    "$(this.api().table().header()).css({'background-color': '#090057', 'color': '#fff'});",
    "}"),lengthMenu = c(5,10,15,20), pageLength = 10,scrollX = TRUE),class = "nowrap cell-border hover stripe",editable = FALSE) 
  })
  
}
runApp(list(ui = ui, server = server), launch.browser = TRUE)

Seems like you are trying to apply filter on a render object which is not what its for
You should use it o the dataframe that you pass to be rendered.
total[,] in your example

thanks for your help,I got it right with ...

 DT::datatable(extensions = 'Buttons',total[,] %>% 
                               filter(
        CustomerName %in% CustomerName(),
        as.Date(Order_Date) %in% as.Date(Order_Date())
      ),options = list(dom = 'Blfrtip',
    buttons =
      list('copy', 'print', list(
        extend = 'collection',
        buttons = c('csv', 'excel', 'pdf'),
        text = 'Download'
      )),initComplete = JS(
    "function(settings, json) {",
    "$(this.api().table().header()).css({'background-color': '#090057', 'color': '#fff'});",
    "}"),lengthMenu = c(5,10,15,20), pageLength = 10,scrollX = TRUE),class = "nowrap cell-border hover stripe",editable = FALSE) 

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.