Issue with GGPlot and Shiny App

Hello,First off this is my first shiny app. I am trying to create an app that takes the user's input of a variable from the data frame I created and then plots that variable against the duration of the agreement variable in the same data frame. The issue seems to be that I cannot get the app to take the input and then use that input to select all the values in that column and plot the graph. If anyone can help I would be beyond appreciative. Here is my code
UI.R

library(shiny)
library(stringr)
library(dplyr)
library(ggplot2)
library(stats)
library(DT)

df <- read.csv('CompressedAgreementData.csv')
colnames(df)[1] <- 'Agreement'
df2 <- read.csv('CompressedAgreementDataTrunc.csv')
colnames(df2)[1] <- 'AgreementDuration'

shinyUI(fluidPage(
    titlePanel('National Economics and the Length of Power-Sharing Agreements'),
    sidebarLayout(
        sidebarPanel(
            varSelectInput(inputId = 'var1', df2[-1], label = 'Variable', selected = 'PoliticalPS',
                        multiple = F),
            actionButton('submit', label = 'Submit')
        ),
    mainPanel(
        plotOutput('plot'),
        dataTableOutput('table')

    )
     )
    ))
    

Server.R

library(shiny)
library(stringr)
library(dplyr)
library(ggplot2)
library(stats)


shinyServer(function(input, output, session) {
    
    output$table <- renderDataTable({
        df[1:5] 
        })
    
    updateVarSelectInput(session, 'var1')
    
    output$plot <- renderPlot({
        req(input$submit)
        req(input$var1)
        ggplot(df, aes(AgreementDuration, input$var1)) + geom_point() + geom_smooth(method = 'lm')

    })
})

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.