newbie to rShiny trying to create a website & does not understand how the server part works

Hi there, I'm new to rShiny and I have been trying to create a website using shiny and I'm stuck at the "server" part as in I do not know how I can render my plots etc, so please help.

To be specific, I generally do not understand the server part when creating a website and I would love for someone to give me a general explanation of the concept.

I'm using the infert dataset, my goal is to explore the relationship between induced and spontaneous abortion vs. infertility.

I would like to create a 'welcome' page that gives my audiences an intro to the issue of abortion and infertility and the definitions of abortion and infertility etc. I would also like to create a second tab that shows a histogram of parity vs abortions. However, I'm stuck on how to go about doing that, like the initial step that I would have to take.

I think what I'm looking for is the general structure of the code for the server part that would allow me to render the written text and the histogram.

here is what I have done so far,


### Define UI for application that draws a histogram
ui <- fluidPage(
  # Application title
  titlePanel("Infertility and Abortions:"),
   p("How does induced and spontaneous abortions affect women's infertility?"),
  # Sidebar
    # Sidebar panel for inputs ----
      # Slider Input for ages in numbers ----
                  label = h3("Age:"),
                  min = 20,
                  max = 50,
                  value = c(30, 40)
      # Checkbox for Education Level ----
      checkboxGroupInput("checkGroup", label = h3("Education Level"), 
                         choices = list("Low Levels of Education" = "0-5yrs", 
                                        "High Levels of Education" = "6-11yrs", 
                                        "Tertiary Levels of Education and Above" = "12+ yrs"),
                         selected = "High Levels of Education"
       # Select Input for Abortions ----
      selectInput("select", label = h3("Abortion Type"), 
                  choices = list("Induced Abortion" = "induced", 
                                 "Spontaneous Abortion" = "spontaneous", 
                                 "Induced and Spontaneous Abortion" = c("induced, spontaneous")), 
                  selected = "Induced Abortion"
    # Main panel for displaying outputs ----
      # Output: Tab-set w/plots, summary
        tabsetPanel(type = "tabs",
                    tabPanel("Welcome", verbatimTextOutput("summary")),
                    tabPanel("Bar Plot", plotOutput("barplot"), br(), 
                             radioButtons("filetype", "Select File Type To Download", 
                                          c("PDF", "JPEG")),
                             downloadButton("dwd", "Download Graph")),
                    tabPanel("Histogram", plotOutput("distPlot")),
                    tabPanel("Summary", verbatimTextOutput("summary"))

### Define server logic to draw the above graphs

# First Install GBM Package

# Define server logic required to draw a histogram
server <- function(input, output) {
  output$hist <- renderPlot({


# Run the application 
shinyApp(ui = ui, server = server)


I suggest you watch the great introduction Tutorial on Shiny

This should explain all the basics.

Hope this helps,

1 Like

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.