You'll just need to run that command inside a reactive expression. So if you already have a function defined in your external .R file that wraps your query, you can call that like so:
output$query <- reactive({
df <- runQuery(datasetInputNumber())
# whatever you want to do to your data here.
output$avg <- mean(df[,2])
...
})
where runQuery
is the function defined in the external R file that accepts a number that then gets used in the SQL query.