I am making a little interactive widget using shiny. The purpose of the widget is not to create a stand-alone shiny web app. Instead, the idea is to run the widget in an interactive R session, to allow the user to interactively manipulate data from the session using a GUI. The output of the Shiny app should then be returned to the user session by the function.
The 'true' purpose of my widget is to interactively select data points on a plot, and return the values selected as the output of the function. However, to make a nice and simple REPREX, I have chosen a simpler scenario:
multiply_me <-
function(number1) {
require(shiny)
shinyApp(
ui = fluidPage(
selectInput('number2', label = 'Enter multiplication factor', choices = c(1, 2, 3)),
textOutput('result')
),
server = function(input, output) {
output$result = renderText(number1 * as.numeric(input$number2))
}
)
}
In the multiply_me function, the user can take a variable from the existing interactive session (number1), and run multiply_me(number1) to initiate the shiny widget. The widget then allows the user to select multiplication factors on the slider and view the result.
But how do I return the result of the calculation (number1 * number 2) to the interactive R session?