Summary of two input in Shiny app

The code below is for a Shiny App. I am trying to create a summary of the input from both dropdown menu. The code runs but no summary is showing. If i can even have the summary on a separate tab. Many Thanks

app_data <- tibble::tribble(
  ~power_draw_watt, ~gpu_temp_c, ~gpu_util_perc,
  131.55,         48L,            92L,
  117.03,         40L,            92L,
  121.64,         45L,            91L,
  50.23,         38L,            90L,
  141.82,         41L,            90L,
  120.5,         43L,            88L,
  121.09,         41L,            91L,
  27.18,         35L,             0L,
  139.63,         43L,            93L,
  77.87,         36L,            90L,
  88.47,         40L,            91L,
  125.88,         43L,            90L,
  42.44,         41L,             0L,
  96.04,         39L,            90L,
  94.27,         42L,            92L,
  146.32,         43L,            93L,
  93.58,         42L,            92L,
  125.01,         51L,            88L,
  71.59,         41L,            89L,
  96.88,         44L,            91L,
  41.38,         38L,             0L,
  129.4,         41L,            86L,
  102.62,         41L,            90L,
  124.08,         41L,            90L,
  155.11,         48L,            93L,
  42.48,         34L,             0L,
  141.29,         41L,            94L,
  143.55,         41L,            94L,
  89.96,         41L,            92L,
  28.67,         39L,             0L,
  39.42,         35L,             0L,
  115.72,         43L,            81L,
  74.24,         42L,            88L,
  121.99,         42L,            92L,
  89.05,         45L,            91L,
  95.33,         38L,            85L,
  119.93,         41L,            91L,
  123.62,         37L,            94L,
  42.21,         37L,             0L,
  102.21,         38L,            90L,
  113.52,         43L,            89L,
  97.03,         46L,            94L,
  137.69,         39L,            91L,
  36.27,         37L,             0L,
  37.23,         35L,             0L,
  136.58,         48L,            93L,
  103.83,         44L,            89L,
  51.29,         41L,             0L,
  47.64,         37L,             0L,
  89.85,         47L,            89L
)

library(shiny)

ui <- fluidPage(
  
  
  selectInput(inputId ="data1",
              label = "choose data1",
              choices = names(app_data),
              selected = NULL
  ),
  selectInput(inputId ="data2",
              label = "choose data 2",
              choices = names(app_data),
              selected = NULL
  ),
  mainPanel(
    plotOutput("plot")
  ))




server <- function(input,output){
  library(ggplot2)
  output$plot <- renderPlot({
    data <- data1[, c(input$data1, input$data2)]
    colnames(data) <- c("col1", "col2")
    ggplot(data,aes(x=col1,y=col2)) +
      geom_point(colour='red') +
      labs(x = input$data1, y = input$data2)
  }, height = 400, width = 600)
  
  output$stats <- renderPrint({
    summary(app_data$data2)
  })
  
}

I think this is close to what you are trying to do, but you really need to learn the basics of shiny, check these resources https://shiny.rstudio.com/tutorial/

library(shiny)
library(ggplot2)
library(dplyr)

ui <- fluidPage(
    
    
    selectInput(inputId ="data1",
                label = "Choose X Variable",
                choices = names(app_data),
                selected = NULL
    ),
    selectInput(inputId ="data2",
                label = "Choose Y Variable",
                choices = names(app_data),
                selected = NULL
    ),
    mainPanel(
        plotOutput("plot"),
        h3("Summary from Y Variable"),
        textOutput("stats")
    ))




server <- function(input,output){
    output$plot <- renderPlot({
        ggplot(app_data,aes(x = !!as.name(input$data1), y = !!as.name(input$data2))) +
            geom_point(colour='red')
    }, height = 400, width = 600)
    
    output$stats <- renderPrint({
        app_data %>%
            select(!!as.name(input$data2)) %>% 
            summary()
    })
    
}

shinyApp(ui = ui, server = server)
1 Like

Thanks for this. I will take a look at the link.

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