single selection is working fine but multiple selection is not working what i am trying to achieve here ,graph must be displayed full by default ,for that purpose I have set (selected=NULL) but it is not working out but I don't know why it is happening.
and when I select the multiple value or use the pickerinput for multiple selection ,it doesn't seems to be working, could anyone guide me through why it is working for single selection but not for multiple selection and why selected=null is not working.
library(shiny)
library(plotly)
library(dplyr)
library(readr)
library(shinydashboard)
library(shinythemes)
library(dashboardthemes)
library(shinyWidgets)
# total<<-read.csv("C:/Users/dell/desktop/ssss.csv")
total<-tibble::tribble(
~Order.ID, ~Order_Date, ~CustomerName, ~State, ~City, ~sales,
"B-25601", "4/5/2017", "Bharat", "Gujarat", "Ahmedabad", 1275L,
"B-25602", "4/6/2017", "Pearl", "Maharashtra", "Pune", 66L,
"B-25603", "4/7/2017", "Jahan", "Madhya Pradesh", "Bhopal", 8L,
"B-25604", "4/8/2017", "Divsha", "Rajasthan", "Jaipur", 80L,
"B-25605", "4/8/2017", "Kasheen", "West Bengal", "Kolkata", 168L,
"B-25606", "4/9/2017", "Hazel", "Karnataka", "Bangalore", 424L,
"B-25607", "4/9/2017", "Sonakshi", "Jammu and Kashmir", "Kashmir", 2617L,
"B-25608", "4/10/2017", "Aarushi", "Tamil Nadu", "Chennai", 561L,
"B-25609", "4/11/2017", "Jitesh", "Uttar Pradesh", "Lucknow", 119L,
"B-25610", "4/12/2017", "Yogesh", "Bihar", "Patna", 1355L,
"B-25611", "4/13/2017", "Anita", "Kerala", "Thiruvananthapuram", 24L,
"B-25612", "4/14/2017", "Shrichand", "Punjab", "Chandigarh", 193L,
"B-25613", "4/14/2017", "Mukesh", "Haryana", "Chandigarh", 180L,
"B-25614", "4/15/2017", "Vandana", "Himachal Pradesh", "Simla", 116L,
"B-25615", "4/15/2017", "Bhavna", "Sikkim", "Gangtok", 107L,
"B-25616", "4/16/2017", "Kanak", "Goa", "Goa", 12L,
"B-25617", "4/16/2017", "Sagar", "Nagaland", "Kohima", 38L,
"B-25618", "4/17/2017", "Manju", "Andhra Pradesh", "Hyderabad", 65L,
"B-25619", "4/17/2017", "Ramesh", "Gujarat", "Ahmedabad", 157L,
"B-25620", "4/18/2017", "Sarita", "Maharashtra", "Pune", 75L,
"B-25621", "4/19/2017", "Deepak", "Madhya Pradesh", "Bhopal", 87L,
"B-25622", "4/20/2017", "Monisha", "Rajasthan", "Jaipur", 50L,
"B-25623", "4/21/2017", "Atharv", "West Bengal", "Kolkata", 1364L,
"B-25624", "4/22/2017", "Vini", "Karnataka", "Bangalore", 476L,
"B-25625", "4/22/2017", "Pinky", "Jammu and Kashmir", "Kashmir", 257L,
"B-25626", "4/23/2017", "Bhishm", "Maharashtra", "Mumbai", 856L,
"B-25627", "4/23/2017", "Hitika", "Madhya Pradesh", "Indore", 485L,
"B-25628", "4/24/2017", "Pooja", "Bihar", "Patna", 25L,
"B-25629", "4/26/2017", "Hemant", "Kerala", "Thiruvananthapuram", 1076L,
"B-25630", "4/27/2017", "Sahil", "Punjab", "Chandigarh", 107L,
"B-25631", "4/28/2017", "Ritu", "Haryana", "Chandigarh", 68L,
"B-25632", "4/28/2017", "Manish", "Himachal Pradesh", "Simla", 781L,
"B-25633", "4/29/2017", "Amit", "Sikkim", "Gangtok", 43L,
"B-25634", "4/29/2017", "Sanjay", "Goa", "Goa", 30L,
"B-25635", "4/30/2017", "Nidhi", "Nagaland", "Kohima", 160L,
"B-25636", "4/30/2017", "Nishi", "Maharashtra", "Mumbai", 259L,
"B-25637", "5/1/2017", "Ashmi", "Madhya Pradesh", "Indore", 1603L,
"B-25638", "5/1/2017", "Parth", "Maharashtra", "Pune", 494L,
"B-25639", "5/2/2017", "Lisha", "Madhya Pradesh", "Bhopal", 98L,
"B-25640", "5/3/2017", "Paridhi", "Rajasthan", "Jaipur", 68L,
"B-25641", "5/4/2017", "Parishi", "West Bengal", "Kolkata", 42L,
"B-25642", "5/5/2017", "Ajay", "Karnataka", "Bangalore", 116L,
"B-25643", "5/6/2017", "Kirti", "Jammu and Kashmir", "Kashmir", 22L,
"B-25644", "5/6/2017", "Mayank", "Maharashtra", "Mumbai", 14L,
"B-25645", "5/7/2017", "Yaanvi", "Madhya Pradesh", "Indore", 305L,
"B-25646", "5/7/2017", "Sonal", "Bihar", "Patna", 362L,
"B-25647", "5/8/2017", "Sharda", "Kerala", "Thiruvananthapuram", 12L,
"B-25648", "5/9/2017", "Aditya", "Punjab", "Chandigarh", 353L,
"B-25649", "5/10/2017", "Rachna", "Haryana", "Chandigarh", 193L,
"B-25650", "5/11/2017", "Chirag", "Maharashtra", "Mumbai", 233L,
"B-25651", "5/12/2017", "Anurag", "Madhya Pradesh", "Indore", 228L,
"B-25652", "5/13/2017", "Tushina", "Goa", "Goa", 333L,
"B-25653", "5/13/2017", "Farah", "Nagaland", "Kohima", 534L,
"B-25654", "5/14/2017", "Sabah", "Maharashtra", "Mumbai", 53L,
"B-25655", "5/14/2017", "Nida", "Madhya Pradesh", "Indore", 158L,
"B-25656", "5/16/2017", "Priyanka", "Maharashtra", "Pune", 149L,
"B-25657", "5/17/2017", "Tulika", "Madhya Pradesh", "Bhopal", 105L,
"B-25658", "5/19/2017", "Shefali", "Rajasthan", "Jaipur", 26L,
"B-25659", "5/21/2017", "Sanskriti", "West Bengal", "Kolkata", 97L,
"B-25660", "4/18/2008", "Shruti", "Karnataka", "Bangalore", 59L,
"B-25661", "4/19/2008", "Subhashree", "Jammu and Kashmir", "Kashmir", 635L,
"B-25662", "4/19/2008", "Sweta", "Maharashtra", "Mumbai", 46L,
"B-25663", "4/20/2008", "Pournamasi", "Madhya Pradesh", "Indore", 1103L,
"B-25664", "4/20/2008", "Pratyusmita", "Bihar", "Patna", 55L,
"B-25665", "4/21/2008", "Chayanika", "Kerala", "Thiruvananthapuram", 45L,
"B-25666", "4/22/2008", "Tanvi", "Punjab", "Chandigarh", 24L,
"B-25667", "4/23/2008", "Anjali", "Haryana", "Chandigarh", 35L,
"B-25668", "4/24/2008", "Rhea", "Himachal Pradesh", "Simla", 1560L,
"B-25669", "4/25/2008", "Piyali", "Sikkim", "Gangtok", 133L,
"B-25670", "4/26/2008", "Charika", "Goa", "Goa", 114L,
"B-25671", "4/26/2008", "Mitali", "Nagaland", "Kohima", 143L,
"B-25672", "4/27/2008", "Akanksha", "Andhra Pradesh", "Hyderabad", 40L,
"B-25673", "4/27/2008", "Arsheen", "Gujarat", "Ahmedabad", 34L,
"B-25674", "4/28/2008", "Mahima", "Maharashtra", "Pune", 42L,
"B-25675", "4/29/2008", "Shreya", "Madhya Pradesh", "Bhopal", 89L,
"B-25676", "4/30/2008", "Chandni", "Rajasthan", "Jaipur", 19L,
"B-25677", "5/1/2008", "Ekta", "West Bengal", "Kolkata", 249L,
"B-25678", "5/1/2008", "Bathina", "Karnataka", "Bangalore", 711L,
"B-25679", "5/2/2008", "Avni", "Maharashtra", "Mumbai", 496L,
"B-25680", "5/25/2008", "Aayushi", "Madhya Pradesh", "Indore", 389L,
"B-25681", "5/3/2008", "Bhawna", "Madhya Pradesh", "Indore", 40L,
"B-25682", "5/4/2008", "Krutika", "Bihar", "Patna", 23L,
"B-25683", "5/4/2008", "Shreya", "Kerala", "Thiruvananthapuram", 382L,
"B-25684", "5/5/2008", "Samiksha", "Maharashtra", "Mumbai", 637L,
"B-25685", "5/6/2008", "Sheetal", "Madhya Pradesh", "Indore", 117L,
"B-25686", "5/7/2008", "Pooja", "Himachal Pradesh", "Simla", 182L,
"B-25687", "5/8/2008", "Sanjna", "Maharashtra", "Mumbai", 880L,
"B-25688", "5/8/2008", "Swetha", "Madhya Pradesh", "Indore", 154L,
"B-25689", "5/9/2008", "Bhaggyasree", "Maharashtra", "Mumbai", 816L,
"B-25690", "5/28/2008", "Gunjan", "Madhya Pradesh", "Indore", 1629L,
"B-25691", "5/10/2008", "Akancha", "Maharashtra", "Mumbai", 68L,
"B-25692", "5/11/2008", "Rashmi", "Madhya Pradesh", "Indore", 314L,
"B-25693", "5/11/2008", "Parna", "Madhya Pradesh", "Bhopal", 122L,
"B-25694", "5/12/2008", "Subhasmita", "Rajasthan", "Jaipur", 22L,
"B-25695", "5/13/2008", "Suhani", "West Bengal", "Kolkata", 434L,
"B-25696", "5/14/2008", "Noopur", "Karnataka", "Bangalore", 1061L,
"B-25697", "5/28/2008", "Vijay", "Jammu and Kashmir", "Kashmir", 50L,
"B-25698", "5/15/2008", "Amisha", "Tamil Nadu", "Chennai", 37L,
"B-25699", "5/16/2008", "Kritika", "Uttar Pradesh", "Lucknow", 263L
)
ui <- dashboardPage(
dashboardHeader(title="dashboard"),
dashboardSidebar(
sidebarMenu(
dateRangeInput(inputId = "date",
label = 'Date range',
start = Sys.Date() - 28, end = Sys.Date() + 2,
format = "mm/dd/yyyy",
separator = "TO"),
selectInput(inputId = "p1",label="filter drop down",choices = c(unique(total$State)),selected = NULL,
multiple = FALSE,selectize = TRUE,width = NULL,size = NULL),
pickerInput(inputId = "p2",label="multiselect",choices = c(unique(total$State))),
pickerInput(inputId = "p3",label = "Select/deselect all options",choices = c(unique(total$State)),
options = list(`actions-box` = TRUE),multiple = TRUE)
)),
dashboardBody(
shinyDashboardThemes(
theme = "onenote"
),
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(input$p1, wt = sales) %>%
plot_ly(x = input$p1, 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())
)
})
}
runApp(list(ui = ui, server = server), launch.browser = TRUE)