Hi all,
This is my first time posting here so I"m hoping that I can share my data in the easiest way.
I'm making an app using R/Shiny.
Everything was working fine and then I added another tab, now the first tab isn't showing anything. I found a similar post, but it was solved by creating unique ids. As far as I can tell, I have unique Ids, I guess there is something else that is now tripping it up.
this code below here works and the tab called "time-series" plots 4 nice graphs.
reshape the data to long format
df_m<- dat %>%
select(!colnames_to_remove) %>%
pivot_longer(names_to="date",values_to="Products_sold",
cols=-c(PID,Name,Category,Area,Main_Category,Sub_Category,Sample_Category,Sample,Analyte,Sample_Volume,Isolation_Method, Product_Size)) %>%
mutate(date=as_date(str_trim(sapply(strsplit(date,"to"),'[', 1),"both")))creating user interface
ui <- fluidPage(theme = shinytheme("yeti"),
titlePanel("Analysis of Product Sales"),tabsetPanel(
## time series panel
tabPanel("time-series", h1("Quarterly Analysis for all Areas by Category"),
sidebarPanel(
textOutput("Choose your date range for analysis"),
dateRangeInput("daterange_t", "Date range:",start="2018-01-01")
),mainPanel( plotOutput("time_plot", click = "time_plot_click"), verbatimTextOutput("plot_clickinfo"), tableOutput("data_table"), width=12) ), # best seller # comparison panel tabPanel("comparisons", h1("Comparative Analyses") )
)
)
server functions
server <- function(input, output, session) {
bestdat<-reactive({
df_m %>%
filter(date > input$daterange1[1] & date < input$daterange1[2] ) %>%
group_by(Name) %>%
summarise(sum_products=sum(Products_sold)) %>%
slice_max(sum_products,n=input$top_numb)
})treemap or barplot
## graph time series plot
timedat<-reactive({
df_m %>%
filter(date > input$daterange_t[1] & date < input$daterange_t[2] ) %>%
mutate(Quarter=quarter(date, type = "date_first", fiscal_start = 11))%>%
group_by(Area,Main_Category,Quarter) %>%
summarise(sum_products=sum(Products_sold))
})output$time_plot <- renderPlot({
dat<-timedat()
font_size=16
p1<-dat %>%
filter(Area==unique(dat$Area)[1])%>%
ggplot(aes(x=Quarter,y=sum_products,color=Main_Category)) +
geom_line(size=1.5) +
geom_point(size=3)+
ggtitle(unique(dat$Area)[1])+
xlab(NULL)+
theme_bw() +
theme(text=element_text(size = font_size))
p2<-dat %>%
filter(Area==unique(dat$Area)[2])%>%
ggplot(aes(x=Quarter,y=sum_products,color=Main_Category)) +
geom_line(size=1.5) +
geom_point(size=3)+
ggtitle(unique(dat$Area)[2])+
xlab(NULL)+
theme_bw() +
theme(text=element_text(size = font_size))
p3<-dat %>%
filter(Area==unique(dat$Area)[3])%>%
ggplot(aes(x=Quarter,y=sum_products,color=Main_Category)) +
geom_line(size=1.5) +
geom_point(size=3)+
ggtitle(unique(dat$Area)[3])+
xlab(NULL)+
theme_bw() +
theme(text=element_text(size = font_size))
p4<-dat %>%
filter(Area==unique(dat$Area)[4])%>%
ggplot(aes(x=Quarter,y=sum_products,color=Main_Category)) +
geom_line(size=1.5) +
geom_point(size=3)+
ggtitle(unique(dat$Area)[4])+
xlab(NULL)+
theme_bw() +
theme(text=element_text(size = font_size))ggarrange(p1,p2,p3,p4,nrow=2,ncol=2)
}, res = 96)
output$plot_clickinfo <- renderPrint({
cat("Click:\n")
str(nearPoints(timedat(), input$time_plot_click))str(input$time_plot_click)
})
output$data_table <- renderTable({
req(input$plot_click)
browser()
nearPoints(timedat(), input$time_plot_click, xvar = "Quarter", yvar = "sum_products")
})}
Run the application
#shiny::runApp(display.mode="showcase")
shinyApp(ui = ui, server = server)
Blockquote
However, when I add another tab (best-sellers in bold). Then the first one doesn't display anything and it doesn't give an error message.
ui <- fluidPage(theme = shinytheme("yeti"),
titlePanel("Analysis of Product Sales"),tabsetPanel(
## time series panel
tabPanel("time-series", h1("Quarterly Analysis for all Areas by Category"),
sidebarPanel(
textOutput("Choose your date range for analysis"),
dateRangeInput("daterange_t", "Date range:",start="2018-01-01")
),mainPanel( plotOutput("time_plot", click = "time_plot_click"), verbatimTextOutput("plot_clickinfo"), tableOutput("data_table"), width=12) ),
> tabPanel("best-sellers", h1("Best Selling Products"),
> sidebarPanel(
> textOutput("Choose your date range for analysis"),
> dateRangeInput("daterange1", "Date range:",start="2018-01-01") ,
> sliderInput("top_numb", "Number of Products:",
> min = 1, max = 25, value = 10,step=1)
> ),
> mainPanel(
> plotOutput("best_tree_plot"),
> width=12)
> ),
# comparison panel tabPanel("comparisons", h1("Comparative Analyses") )
)
here is a subset of my data if you would like to run it.
dput(df_m[500:550,])
structure(list(PID = c(27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L,
27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L,
27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L,
27L, 27L, 27L, 27L, 27L, 27L, 27L, 29L, 29L, 29L, 29L, 29L, 29L,
29L, 29L, 29L, 29L), Name = structure(c(84L, 84L, 84L, 84L, 84L,
84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L,
84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L,
84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L, 67L, 67L, 67L,
67L, 67L, 67L, 67L, 67L, 67L, 67L), levels = c("100b RNA Ladder",
"16S V3-V4 Library Preparation Kit for Illumina", "16S V3-V4 Library Preparation Kit for Illumina (Set A)",
"16S V3-V4 Library Preparation Kit for Illumina (Set B)", "16S V3-V4 Library Preparation Kit for Illumina (Set C)",
"16S V3-V4 Library Preparation Kit for Illumina (Set D)", "16S V3-V5 Library Preparation Kit for Illumina",
"16S V3-V5 Library Preparation Kit for Illumina (Set A)", "1kb RNA Ladder",
"50 bp DNA Ladder", "AAV Purification Maxi Slurry Kit ", "AAV Purification Midi Kit",
"AAV Purification Mini Kit", "Animal Tissue RNA Purification Kit",
"Aspergillus niger TaqMan PCR Kit", "Bacterial Genomic DNA Isolation 96-Well Kit",
"Bacterial Genomic DNA Isolation Kit", "Biofilm DNA Isolation Kit",
"Blood DNA Isolation 96-Well Kit (Magnetic Bead System)", "Botrytis cinerea TaqMan Probe/Primer and Control Set",
"Candida albicans TaqMan Probe/Primer and Control Set", "Cell Lysis Reagent",
"Cells and Tissue DNA Isolation 96-Well Kit (Magnetic Bead System)",
"Cladosporium cladosporioides TaqMan PCR Kit", "Cladosporium cladosporioides TaqMan Probe/Primer and Control Set",
"CleanAll DNA/RNA Clean-Up and Concentration Micro Kit", "Clone Sizer 100bp DNA Ladder",
"Collection Tubes", "Cytoplasmic & Nuclear RNA Purification Kit",
"Direct DNA Extraction Kit (Bacteria)", "DNA Gel Extraction Kit",
"Elution Tubes", "Elution Tubes ", "Endotoxin Removal Kit (Maxi) - For DNA",
"Endotoxin Removal Kit (Mini) - For DNA", "Erwinia amylovora TaqMan PCR Kit",
"FastRunner DNA Ladder", "FBS Exosome Depletion Kit I (Column Format)",
"FBS Exosome Depletion Kit I (Slurry Format)", "FBS Exosome Depletion Kit II (Column Format)",
"FBS Exosome Depletion Kit II (Slurry Format)", "FFPE RNA Purification 96-Well Kit",
"FFPE RNA Purification Kit", "Full Ranger 100 bp DNA Ladder",
"FullRanger 100bp DNA Ladder", "Genomic DNA Isolation Kit", "H1N1 TaqMan RT-PCR Kit",
"HBV TaqMan PCR Kit", "HBV TaqMan Probe/Primer and Control Set",
"HighRanger 1kb DNA Ladder", "HighRanger Plus 100bp DNA Ladder",
"HIV Quantitative TaqMan RT-PCR Detection Kit", "HIV TaqMan Probe/Primer and Control Set",
"HIV TaqMan RT-PCR Kit", "HPV High and Low Risk TaqMan PCR Kit",
"HPV High and Low Risk TaqMan Probe/Primer and Control Set",
"HPV High Risk TaqMan PCR Kit", "HPV High Risk TaqMan Probe/Primer and Control Set",
"HSV-1 TaqMan Probe/Primer and Control Set", "HSV-1&2 TaqMan PCR Kit",
"HSV-1&2 TaqMan Probe/Primer and Control Set", "Inclusion Body Solubilization Reagent",
"Leukocyte RNA Purification Kit", "Leukocyte RNA Purification Plus Kit ",
"Listeria monocytogenes TaqMan PCR Kit", "Listeria monocytogenes TaqMan Probe/Primer and Control Set",
"LowRanger 100bp DNA Ladder", "microRNA Purification Kit", "MidRanger 1kb DNA Ladder",
"Milk Bacterial DNA Isolation Kit", "MiniSizer 50bp DNA Ladder",
"Mycoplasma TaqMan PCR Kit", "Mycoplasma TaqMan Probe/Primer and Control Set",
"Neisseria gonorrhoea TaqMan PCR Kit", "NGS Library Quantification Kit (for Small RNA-Seq)",
"NGS Normalization 96-Well Kit", "Olive Oil DNA Isolation Kit",
"On-Column Proteolytic Digestion Kit", "PCR and Sequencing Reaction Clean-Up 96-Well Kit (Magnetic Bead System)",
"PCR Purification - 96 Well Kit", "PCR Purification Kit", "PCR Ranger 100bp DNA Ladder",
"PCR Ranger 100bp DNA Ladder", "PCR Sizer 100 bp DNA Ladder",
"PCR Sizer 100bp DNA ladder", "Penicillium sp. TaqMan PCR Kit",
"Penicillium sp. TaqMan Probe/Primer and Control Set", "Phage DNA Isolation Kit",
"Plant DNA Isolation 96-Well Kit (Magnetic Bead System)", "Plant RNA-DNA Purification Kit",
"Plant/Fungi DNA Isolation Kit", "Plant/Fungi Total RNA Purification",
"Plant/Fungi Total RNA Purification Kit", "Plasma/Serum Circulating and Exosomal RNA Purification Maxi Kit (Slurry Format)",
"Plasma/Serum Circulating and Exosomal RNA Purification Mini Kit (Slurry Format)",
"Plasma/Serum Circulating DNA Purification Maxi Kit (Slurry Format)",
"Plasma/Serum Circulating DNA Purification Midi Kit (Slurry Format)",
"Plasma/Serum Circulating DNA Purification Mini Kit (Slurry Format)",
"Plasmid MiniPrep 96-Well Kit (Magnetic Bead System)", "Plasmid MiniPrep Kit",
"PPV TaqMan Probe/Primer and Control Set", "PPV TaqMan RT-PCR Kit",
"Proteinase K", "Proteinase K ", "Proteinase K - 12 mg", "Proteinase K ",
"ProteoSpin Total Protein Concentration Detergent Clean-Up And Endotoxin Removal Maxi Kit",
"ProteoSpin Total Protein Concentration Detergent Clean-Up and Endotoxin Removal Mini Kit",
"ProteoSpin?? Abundant Serum Protein Depletion Kit", "ProteoSpin?? Inclusion Body Protein Isolation Maxi Kit",
"ProteoSpin?? Inclusion Body Protein Isolation Micro Kit", "ProteoSpin?? Urine Protein Concentration Kit",
"ProteoSpin?? Urine Protein Concentration Maxi Kit", "RBC Lysis Buffer",
"RBC Lysis Solution", "RNA Clean-Up and Concentration 96-Well Kit",
"RNA Clean-Up and Concentration Kit", "RNA Preserve", "RNA Preserve ",
"RNA/DNA Purification Micro Kit", "Rnase-Free DNase I Kit", "RNase-Free DNase I Kit",
"RNAse A 28000U", "RSV-A TaqMan RT-PCR Kit", "Saccharomyces cerevisiae TaqMan Probe/Primer and Control Set",
"Saliva DNA Collection and Preservation Devices", "Saliva DNA Isolation 96-Well Kit",
"Saliva DNA Isolation 96-Well Kit (Magnetic Bead System)", "Saliva DNA Isolation Kit",
"Saliva DNA Isolation Kit (Magnetic Bead System)", "Saliva DNA Isolation Reagent Kit (Up to 4 mL)",
"Saliva RNA Collection and Preservation Devices", "Salmonella enterica TaqMan Probe/Primer and Control Set",
"Small RNA Library Prep Kit for Illumina (Indexes 1-24)", "Small RNA Library Prep Kit for Illumina (Indexes 25-48)",
"Soil DNA Isolation 96-Well Kit (Magnetic Bead System)", "Soil DNA Isolation Maxi Kit",
"Staphyloccocus aureus TaqMan Probe/Primer and Control Set",
"Stool DNA Isolation 96-Well Kit (Magnetic Bead System)", "Stool Nucleic Acid Collection and Preservation System (50)",
"Streptococcus agalactiae TaqMan PCR Kit", "Streptococcus agalactiae TaqMan Probe/Primer and Control Set",
"Streptococcus uberis TaqMan Probe/Primer and Control Set", "Total RNA Purification Kit",
"Total RNA Purification Kit ", "Total RNA Purification Kit - 96 Deep Well Plate Format",
"Total RNA Purification Kit - 96 Well Plate Format", "Total RNA Purification Kit - 96 Well Plate Format ",
"UltraRanger 1kb DNA Ladder", "Urine Collection and Preservation Cup (120 cc) ",
"Urine Collection and Preservation Tube (15 cc)", "Urine Collection and Preservation Tube (5 cc)",
"Urine Collection and Preservation Tube (50 cc)", "Urine Collection and Preservation Tube 15cc",
"Urine Collection and Preservation Tube 50cc", "Urine Collection and Preservation Tube 5cc",
"Urine DNA Isolation Kit", "Urine Exfoliated Cell and Bacteria RNA Purification Kit",
"Urine Preservation Solution Single Dose Format", "Urine Preservative",
"Water RNA/DNA Purification Kit", "Water RNA/DNA Purification Kit (0.22 ??m)",
"Water RNA/DNA Purification Kit (0.45 ??M)", "XMRV TaqMan Probe/Primer and Control Set",
"XMRV TaqMan RT-PCR Kit"), class = "factor"), Category = structure(c(5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L), levels = c("Bottled Enzyme", "Bottled Solution", "Diagnostic Kits",
"DNA Kits", "DNA Ladders", "Multi-Analyte Kits", "Packaged Tubes",
"Primer Sets and Controls", "Protein Kits", "RNA Kits", "RNA Ladders",
"Urine Collection and Preservation"), class = "factor"), Area = structure(c(4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L), levels = c("Analysis", "Collection/Preservation", "Isolation_and_Purification",
"Lab_Supplies"), class = "factor"), Main_Category = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L), levels = c("DNA and RNA ladders", "DNA kits", "Enzymes",
"exosome kits", "multi-analyte kits", "NGS", "Packaged Tubes",
"PCR", "Preservation Device", "Preservation Reagent", "protein kits",
"Reagent", "RNA kits", "virus kit"), class = "factor"), Sub_Category = structure(c(7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L), levels = c("", "AAV", "diagnostic_kits", "DN", "DNA clean-up",
"DNA Isolation", "DNA Ladders", "DNA/RNA clean-up", "DNA/RNA Isolation",
"Exo clean-up", "NGS_library_kits", "NGS_reagents", "primers_controls",
"proK", "Protein clean-up", "Protein Isolation", "RBCs", "RNA clean-up",
"RNA Isolation", "RNA Ladders"), class = "factor"), Sample_Category = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L), levels = c("", "bodily_fluids", "cells and tissue",
"environmental", "food", "lab_process", "microbial", "multi-sample"
), class = "factor"), Sample = structure(c(1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), levels = c("",
"bacteria", "biofilm", "blood", "cells and tissue", "endotoxin removal",
"FBS", "FFPE", "milk", "multi-sample", "olive oil", "PCR cleanup",
"phage", "plant/fungi", "plasma/serum", "saliva", "soil", "stool",
"urine", "water"), class = "factor"), Analyte = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L), levels = c("", "cfDNA", "cfRNA", "fractionated_RNA",
"microRNA", "plasmid", "protein", "totDNA", "totDNA/totRNA",
"totRNA"), class = "factor"), Sample_Volume = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L), levels = c("", "DWP", "maxi", "micro", "midi", "mini"
), class = "factor"), Isolation_Method = structure(c(1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L), levels = c("", "chemical_reagents", "filter plates", "magbeads",
"slurry", "spin column"), class = "factor"), Product_Size = c(NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_
), date = structure(c(18440, 18470, 18501, 18532, 18562, 18593,
18623, 18654, 18685, 18713, 18744, 18774, 18805, 18835, 18866,
18897, 18927, 18958, 18988, 19019, 19050, 19078, 19109, 19139,
19170, 19200, 19231, 19262, 19292, 19323, 19353, 19384, 19415,
19443, 19474, 19504, 19535, 19565, 19596, 19627, 19657, 17862,
17892, 17923, 17954, 17982, 18013, 18043, 18074, 18104, 18135
), class = "Date"), Products_sold = c(0L, 0L, 0L, 0L, 0L, 0L,
3L, 0L, 0L, 2L, 0L, 2L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 16L, 3L, 9L, 5L, 4L, 0L, 11L, 12L, 16L, 4L)), row.names = c(NA,
-51L), class = c("tbl_df", "tbl", "data.frame"))Preformatted text