I have issue with checkboxGroupInput() in shiny dashboread
I want the scatter plot to be plotting based on the gender selection, meaning when I put a check on the male, only the male part is drawn, so on for the female part, and when check all then will display all dataset
This error appears when selecting female (ERROR: Aesthetics must be either length 1 or the same as the data (3889): x, y and colour)
Also, i have selectInput() to select x axis and y axis and radioButtons() to select coorelation methods but it all works without issue
i try the following code but it does not work
#UI
tabItem(tabName = "corr1",
fluidRow(
column(8,h2("Scatter plot correlation")),
box(selectInput("var1","Select one variable for X axis",choices = names(dfs)) ),
box(selectInput("var2","Select one variable for Y axis",choices = names(dfs)) )),
fluidRow(
box(background="light-blue",
width = 8, girafeOutput("plot2",width = "100%", height = "500px")),
column(2, h3("Gender") , checkboxGroupInput('g', label = p("Select the gender to plot"),
choices =
unique(dfs$Gender),
selected = list("Male","Female"))),
column(2, h3("Correlation methods"), radioButtons('c', label = p("Select one method"),
choiceNames =
list("pearson" , "kendall" ,"spearman"),
choiceValues =
list("pearson" , "kendall" ,"spearman"),
selected = "pearson"))
)
#SERVER
plot<-reactive({
filter(dfs, Gender%in%input$g)
})
myplot2 <- reactive({
x1=as.numeric(dfs[[input$var1]])
y1=as.numeric(dfs[[input$var2]])
if(input$c=="pearson"){ c= cor.test(x1, y1, na.omit=TRUE,method="pearson")}
if(input$c=="spearman"){ c= cor.test(x1, y1, na.omit=TRUE,method="spearman")}
if(input$c=="kendall"){ c= cor.test(x1, y1, na.omit=TRUE,method="kendall")}
# c= cor.test(x1, y1, na.omit=TRUE)
a=round(c$p.value,3)
b=round(c$estimate,3)
x_str = paste0("P-value = " ,a ,"\n", input$c," correlation coefficient = ",b)
scatter=ggplot(plot(), aes(x=x1, y=y1, color=dfs$Gender)) +
geom_point_interactive(size=2.5,tooltip=dfs$p_ID,data_id=dfs$p_ID,position=position_jitter(h=5,w=2)) + #jitter solve the overlapping issue
theme_ipsum()+
stat_smooth(method = "lm",
col = "#C42126",
se = FALSE,
size = 1)+
xlab(input$var1)+
ylab(input$var2)
})
##############
output$plot2 <- renderGirafe({
p2<- girafe(ggobj = myplot2(),width_svg = 14, height_svg = 8,
options = list(
opts_sizing(rescale = FALSE) ,opts_toolbar(saveaspng = FALSE),opts_tooltip(use_fill = TRUE)))
p2
})