How to visualize multiple graph in shiny dashboard?

I tried to visualize all the graphs but the upper one did not appear. I want to know what is missing. the server code for the bar graph works but for the histogram dose not appear.

ui <- fluidPage(
  titlePanel("Country Salary"),
  p("Explore the difference between people who earn less than 50K and more than 50K. You can filter the data by country, then explore various demogrphic information."),
  # TASK 2: Add first fluidRow to select input for country
           wellPanel(selectInput("country", "Select Country",c("United-States", "Canada", "Mexico", "Germany", "Philippines"))  # add select input
  # TASK 3: Add second fluidRow to control how to plot the continuous variables
             p("Select a continuous variable and graph type (histogram or boxplot) to view on the right."),
             radioButtons( "continuous_variable","Continuos variable",choices = c("age" , "hours_per_week")),   # add radio buttons for continuous variables
             radioButtons("graph_type","Graph", choices = c("histogram","boxplot"))    # add radio buttons for chart type
    column(9, plotOutput("P1"))  # add plot output
  # TASK 4: Add third fluidRow to control how to plot the categorical variables
             p("Select a categorical variable to view bar chart on the right. Use the check box to view a stacked bar chart to combine the income levels into one graph. "),
             radioButtons("categorical_variable","Category",choices = c("education", "workclass", "sex")),    # add radio buttons for categorical variables
             checkboxInput("is_stacked", "Bars stacked")    # add check box input for stacked bar chart option
    column(9,  plotOutput("p2"))  # add plot output
# Load libraries

# Read in data
adult <- read_csv("adult.csv")
# Convert column names to lowercase for convenience 
names(adult) <- tolower(names(adult))

# Define server logic
shinyServer(function(input, output) {
  df_country <- reactive({
    adult %>% filter(native_country == input$country)
  # TASK 5: Create logic to plot histogram or boxplot
  output$p1 <- renderPlot({
     ggplot(df_country(), aes_string(x = input$continuous_variable)) +
        geom_histogram()+  # histogram geom
        labs(y= "Number of P", title = paste("Trend of",input$continuous_variable))+  # labels
        facet_warp(~Prediction) # facet by prediction
  # TASK 6: Create logic to plot faceted bar chart or stacked bar chart
  output$p2 <- renderPlot({
    # Bar chart
    p <- ggplot(df_country(), aes_string(x = input$categorical_variable)) +
      labs(y= "Number of P", title = paste("Trend of",input$categorical_variable)) +  # labels
      theme(axis.text.x= element_text(angle = 45 ),legend.position = "bottom")   # modify theme to change text angle and legend position
    if (input$is_stacked) {
      p + geom_bar(aes(fill = prediction))  # add bar geom and use prediction as fill
      p + 
        geom_bar(aes(fill = input$categorical_variable)) + # add bar geom and use input$categorical_variables as fill 
        facet_wrap(~prediction )  # facet by prediction

You have



output$p1 <- renderPlot({

Notice that one is a lower case p and the other is an upper case P. Change one of then so that they match.

This topic was automatically closed 21 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.