Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201945

changing variables of a separate R script in a shiny app

$
0
0

I have a set of scripts which are run from below, with aspects of the final output influenced by lines 2-4

setwd() 
inputyear = ""
inputmonth = ""
dataType = ""

source("1.R")
source("2.R")
source("3.R") 
source("4.R")
source("5.R")

#input required file name
saveWorkbook(wb, "Workbook.xlsx", overwrite = TRUE)

I'd like to be able to change the input year, input month, dataType and the name of the workbook produced by the source() 1-5, from a shiny app, and then run the respective files and generate the excel file.

So far I have the following code, which does not produce any errors, but does not function as desired. I have only included the 'server' section of the code to save space, and this is the part I need help with if possible;

ui<-shinyUI(fluidPage(theme = shinytheme("flatly"),

                      tags$head(
                        tags$style(HTML(
                          ".shiny-output-error-validation {
                          color; green;
                          }
                          "))
                        ),

                      basicPage(
                        headerPanel("Workbook"),
                        sidebarPanel(
                          selectInput("inputmonth","Select Publication Month",c("JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC")),
                          selectInput("inputyear","Select Year",c("2018/19","2019/20","2020/21")),
                          selectInput("dataType","Select Version",c("provisional","final"))),
                        textInput("WorkBookName","Enter File Name (include .xlsx)"),
                        actionButton("Generate", "Generate Workbook"))
                        ))


server <- function(input, output, session){
  observeEvent(input$Generate, {
    validate(need(input$WorkBookName != "", "Please enter file name"))

    req(input$inputmonth, input$inputyear, input$dataType, input$WorkBookName)

    inputyear = input$inputmonth
    inputmonth = input$inputyear
    dataType = input$dataType

    source("1.R",local = TRUE)
    source("2.R", local = TRUE)
    source("3.R", local = TRUE) 
    source("4.R", local = TRUE)
    source("5.R", local = TRUE)


    saveWorkbook(wb, paste0(input$WorkBookName, ".xlsx"), overwrite = TRUE)
  })
}

shinyApp(ui, server)

How can I alter the server script to get the desired functionality?

edit: Full script added, sourced names removed


Viewing all articles
Browse latest Browse all 201945

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>