Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8999217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:09:02+00:00 2026-06-16T00:09:02+00:00

I started playing with Shiny recently. I was trying to write something to demonstrate

  • 0

I started playing with Shiny recently. I was trying to write something to demonstrate central limit theorem. my code is as follows:

ui.R:

#****************************************ui.R file code*****************************

library(shiny)
shinyUI(pageWithSidebar(headerPanel("Central Limit Theorem"),
                        sidebarPanel(selectInput("Distribution", 
                                                 "Distribution:", 
                                                 list("normal", "lognormal")),
                                                 br(),
                                                 sliderInput("sam_size", 
                                                              "Sample size:", 
                                                              min = 5, 
                                                              max = 500, 
                                                              value = 5)
                        ),
                        mainPanel(tabPanel("Plot", plotOutput("plot")))
))

server.R:

#****************************************server.R file code**************************
library(shiny)
shinyServer(function(input, output){
        data <- reactive(function(){Distribution <- switch(input$Distribution,
                                                           normal = rnorm,
                                                           lognormal = rlnorm,
                                                           rnorm
                                                           )
                                    Distribution(input$sam_size*2000)})

        output$plot <- reactive(function(){
                            Distribution <- input$Distribution
                            sam_size <- input$sam_size
                            temp <- matrix(data(), ncol=2000)
                            xbars <- colMeans(temp)
                            hist(xbars, main=paste("Sampling Distribution of the Mean Based on a", Distribution,
                         "distribution with n =", sam_size))})
})

When I tried to run the code using runApp(), below is what I got. As you can see, the plot is not displayed.

enter image description here

The weird part is that, when I went back to my Rstudio, and pressed “Esc” to exit the app, the plot displayed in my Rstudio as shown below:

enter image description here

I wonder if anyone knows what the problem is with my code. Thanks!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:09:03+00:00Added an answer on June 16, 2026 at 12:09 am

    You want to wrap your plotting function with reactivePlot(...), rather than just reactive(...).

    In general, reactive(...) should be used for helper functions in your server that deliver input-dependent data to output functions. Functions that actually generate output objects, however, should be wrapped with the specialized reactive functions, such as reactiveText, reactivePrint, reactiveTable, and reactivePlot.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently started playing with databases, trying to teach myself using examples. I
I just started playing around with threading today and I ran into something that
I started playing with the new graph api with the python sdk. I'm trying
I recently started playing around with writing Perl (v5.8.8) extensions using XS. One of
I started playing with Racket pattern matching system recently and got into a problem
I just started playing with Berkeley DB a few days ago so I'm trying
I've recently started playing around with ASP.NET and I was just about to connect
Just started playing with Android and I'm trying to create an app that has
I've recently started playing around with Specflow, and generating test cases based on the
I started playing with Angular.js recently, and got a demo project working pretty well.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.