質問

In my ui.R I am trying to capture the number entered from a textbox

textInput(inputId="dataSize", label="Choose Number of Rows", value = 1000)

And in my server.R I am trying to reactively get this value and create the output

datasetInputNumber <- reactive ({ input$dataSize })
output$number <- renderPrint({   datasetInputNumber()  })

I then have a separate .R file where I want to pass this number to a sql query

query <- sprintf("select * FROM Table limit %s;", limit)
result <- dbGetQuery(connectionString, query)

How can I get the output number into this previous .R file and set it to "limit"? The .R file is sitting in the correct directory and is being loaded by the server.R

Thanks,

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top