11

I have some data sets that are in a weird format and have written some python scripts to convert to csv format to use in R. Is it possible to call the python scripts in an R shiny app?

1
  • I think the answer is yes. You can use system to run python scripts. Alternately, you might be able to make use of rpy2 to persist values across the python and R sessions. Commented Jul 23, 2014 at 2:48

2 Answers 2

12

Here is a minimal Shiny app that makes use of rPython to execute python calls.

library(shiny)
library(rPython)

ui = bootstrapPage(
  sliderInput('x', 'Set x', 0, 10, 5),
  verbatimTextOutput('out1')
)

server = function(input, output, session){
  output$out1 <- renderPrint({
    python.call("len", 1:input$x)
  })
}

runApp(list(ui = ui, server = server))
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! Do you know if there is an way to install for R 3.1.0?
Will this work after you publish the app online to shinyapps.io? See related question here: stackoverflow.com/questions/32829995/…
3

I know the topic is close but now you can make shinyApp with python using reticulate.

This is a minimalist example.

library(reticulate)
library(shiny)

ui <- fluidPage(
  plotOutput(outputId = "plot01")
)

server <- function(input, output){

  # Import module
  plt <- import("matplotlib.pyplot")

  output$plot01 <- renderPlot({
    plt$plot(1:10)
    plt$show()
  })
}

shinyApp(ui, server)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.