1

thanks for your time.

This is a small general question, and I hope it's not a duplicate. I did quite a bit of looking around, and couldn't find an exact answer to my question.

I have a question about the capabilities of R Shiny. I have never used R shiny before, and am wondering if it can solve a business related problem I have.

I created an R script that takes an imported file, manipulates it, and exports a new file.

My question is this: Could R Shiny be used to build an app that could do all this in a web-based setting?

In particular, I want others to run my R script, without having to use R. If R shiny has the ability to do this, this may solve my problem.

Thanks for your time!

Ethan Wicker
  • 526
  • 7
  • 14

2 Answers2

5

This is my first answer but i worked a lot with Shiny.

Of course you can do what you ask for. You just need to merge the fileInput function and the downloadButton / downloadLink.

https://shiny.rstudio.com/reference/shiny/1.0.4/downloadButton.html

https://shiny.rstudio.com/gallery/file-upload.html

Here i wrote a quick example, you just need to copy and save with the name app.R :

library(shiny)

# Define UI for data upload app ----
ui <- fluidPage(

  # App title ----
  titlePanel("Welcome to Ethar data transformation app"),
  # App subtitle
  h4(HTML("Upload your file and click the Download button")),


  # Sidebar layout with input and output definitions ----
  sidebarLayout(

    # Sidebar panel ----
    sidebarPanel(

      # Input: Select a file ----
      fileInput("fileUploaded", "Choose CSV File",
                multiple = FALSE,
                accept = c("text/csv",
                           "text/comma-separated-values,text/plain",
                           ".csv")),

      # Output: Download a file ----
      downloadButton('downloadFile', 'Process the file & Download', class= "action"),

      # CSS style for the download button ----
      tags$style(type='text/css', "#downloadFile { width:100%; margin-top: 35px;}")


    ),

    # Main panel for displaying outputs ----
    mainPanel(

      # Output: Data file ----
      textOutput("done")

    )
  )
)
# Define server logic to read selected file ----
server <- function(input, output) {


  # Download handler in Server
  output$downloadFile <- downloadHandler(
    filename = function() {
      paste('dataProcessed-', Sys.Date(), '.csv', sep='')
    },
    content = function(con) {
      originalData <- input$fileUploaded
      ##############################
      # Transformations in originalData object
      ##############################
      dataProcesed <- originalData
      write.csv(dataProcesed, con)
      output$done <- renderText({
        ifelse(!is.null(dataProcesed),"Transformation done! :D","Error during the process :(")
      })
    }
  )


}

# Create Shiny app ----
shinyApp(ui, server)

Hope it helps! :)

2

Yes, shiny can do this, the user can input the file, you can run the transformations in a reactive function, and create a download button on your page. You can format the page anyway you like, as well, with HTML and CSS capabilites, as well as javascript.

For more information, you can see: Help users download data from your app and Help users upload files to your app

automa7
  • 494
  • 4
  • 15