Home:ALL Converter>How can I reference a data frame created in an R Script started from a Shiny App

How can I reference a data frame created in an R Script started from a Shiny App

Ask Time:2019-06-28T00:04:05         Author:Alex

Json Formatter

I have already asked this question but realised I wasnt being clear enough in my description of the problem and have therefore deleted the original post.

I have two components at play here. First I have my Shiny App, which is shown below:

library(shiny)
library(readxl)
Pre_Match_Odd_Entry <- read_excel("~/Pre Match Odd Entry.xlsx")

ui <- fluidPage(
  numericInput("code","Code:",1),
  numericInput("min","Minute:",1),
  numericInput("hg","Home:",0),
  numericInput("ag","Away:",0),
  numericInput("edge","Edge:",0.02),
  actionButton("runScript", "Get odds"),

  tableOutput("market")
)

server <- function(input, output, session) {

  mylist <- reactiveVal()

  observe({ # create the list
    mylist(list(
      i_code = input$code,
      i_min = input$min,
      i_hg = input$hg,
      i_ag = input$ag,
      i_edge = input$edge
      ))
  })

  observeEvent(input$runScript, {
    source('~/R/Projects/Scripts/Mean Extraction.R', local = list2env(mylist()))
  })
  output$market <- renderTable({ market })
}

shinyApp(ui, server)

I take the inputs that the user provides from the shiny app and pass it through to my R Script, which runs a calculation and outputs a data frame, which I want to show in my Shiny App after clicking the "Get Odds" button. This code is outlined below, showing only the inputs from the shiny app and then the final line of the code, which is the data frame output.

# Start R Script #
CODE = i_code
minute = i_min
hs = i_hg
as = i_ag
edge = i_edge

...
(calculations)
...
market <- data.frame(...)

# End R Script#

When I run my shiny app, the error I get is the following: Error in source(market) : object 'market' not found

How do I correctly reference this table in my Shiny code so that I can display the table when I press the "Get Odds" button?

Thanks in advance for your help!

Author:Alex,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/56794923/how-can-i-reference-a-data-frame-created-in-an-r-script-started-from-a-shiny-app
yy