I am trying to pass a expression into the ggplot of r shiny app and generate the graph, however it seems not working . Any suggestion is appreciated
in the code below, i am trying to render a plot where i am using the input$xaxis and input$yaxis, while i pass the input$xaxis which is a character needs to be considered as a variable in aes(), so instead of using the aes() i am using the aes_string(). Now, i am trying to pass an expression so that i can reorder the input$xaxis with a variable. but its not working.
output$plot2 <- renderPlot({
req(input$para, input$yaxis)
if (input$xaxis=='ady') {
xaxis <- expr('ady')
} else if (input$xaxis=='visit') {
xaxis <- parse_expr("reorder(input$xaxis, 'visitnum')")
} else if (input$xaxis=='avisit') {
xaxis <- expr(reorder(input$xaxis, 'avisitn'))
}
ggplot(advs %>% filter(usubjid==input$subj & param==input$para), aes_string(x=eval_tidy(xaxis),y=input$yaxis, group='atpt')) +
geom_line(aes(color=atpt)) +
ggtitle(paste(input$para, 'Line Plot'))
})