raw data I'm creating an Rshiny app that will allow a user to upload some clinical data, and view several different plots, based on the tabs they open. These include a line plot, pie chart, and mosaic plot. I'm able to view the line plot and pie chart, based on the uploaded data and user inputs, but having trouble getting the mosaic plot to appear. I get an error that says "object 'input' not found."
I tried to use the ggmosaic(geom_mosaic), and structable packages in R to display the plot. In my data table of interest, there are 5 columns: REF(reference method result for 2x2 contingency table, which is binary -- either POS or NEG clinical result), Result(4 diff values: True Positive, False negative, True negative, false positive), Value(number of patients for each result), SampleType(type of patient sample-- NS,NP, Overall are the 3 possible data values for this column) and Comparator(POS or NEG clinical result). In parenthesis, I have included the types of values one would expect for each column. Furthermore, For my R shiny mosaic app, I have several user inputs on the left hand side, which will allow the app to be constructed once the user has selected them: select input for REF column, select input for Sample type column, select input for comparator. I have code written inside the server function that uses these 3 inputs to construct the mosaic plot.
EDIT: I have attached my raw data in the link at the very top titled "raw data."
mosaic plot data table - takes data from pie chart, but displays it in a #different visual format
MosaicDF <- reactive({
#display mosaic
Mosaic_filtered <- select(PieData_extracted(),-c(3,5:7))
#data transformation
names(Mosaic_filtered)[1]<-"REF"
Mosaic_filtered$SampleType <- "NS"
Mosaic_filtered$Comparator <- c("POS","NEG","NEG","POS")
Mosaic_filtered$REF <- c("POS","POS","NEG","NEG")
Mosaic_filtered$F2 <- factor(as.character(Mosaic_filtered$Value))
MYRaw <- Mosaic_filtered[rep(rownames(Mosaic_filtered),as.numeric(as.character(Mosaic_filtered$F2))), ]
MYRaw <- as.data.frame(MYRaw)
#update select input for mosaic plot
updateSelectInput(session, inputId = 'REF', label = 'Select Reference column',
choices = names(MYRaw), selected = "")
updateSelectInput(session, inputId = 'SampleType', label = 'Select Sample Type column',
choices = names(MYRaw), selected = "")
updateSelectInput(session, inputId = 'Comparator', label = 'Select Comparator column',
choices = names(MYRaw), selected = "")
return(MYRaw)
})
#display mosaic plot
output$mosaic <- renderPlot({
ggplot(data=MosaicDF())+geom_mosaic(aes(x=product(input$REF,input$Comparator),fill=input$REF))+labs(x="Comparator",y="REF")
})
}
I'm getting the data table(from which the mosaic plot is constructed) to appear as an output, but the mosaic plot itself won't show up. It says:
"Error: object input not found".
The pie chart data table and pie chart itself do appear on the tab for this plot. (There are 3 tabs for each of the different plots within the R shiny app, of which the user can select any of these, choose some inputs from a dropdown menu, and allow an app to be automatically built based on the inputs).
I'm wondering if there's a way to modify the code for either my reactive data table or the plot itself-- should I change my code for ggplot, or use a different mosaic package for the Rshiny format?