How to get normal distribution curve in rshiny?

I have the code below, but I get only the histogram and not the normal dist. curve as an overlay:

        ggplot(data = df, aes_string(x = input$x)) +
        geom_histogram(aes(y =..density..),color = "black",fill = "blue", binwidth = input$bins, 
        alpha = 0.2)  +
        stat_function(fun = dnorm, args = list(mean = mean(input$x), sd = sd(input$x)))

I am also trying to calculate the mean and sd for input x but not succeeded either. I think in both cases rshiny needs a specific syntax, I could not find any info about the topic, which explains; how to handle these situations when you upload your file and trying to calculate mean and sd for selected x (input$x), the code:

    output$mean <- renderPrint({
    var <- input$x
    df <- Dataset()
    xdata <- df$var
    mean <- mean(xdata, na.rm = T)
    mean

Thanks in advance and take care out there.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.