Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to run a python script in R shiny

Tags:

python

r

shiny

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?

like image 658
user3646105 Avatar asked Jul 23 '14 02:07

user3646105


People also ask

Can you run a Python script in R?

You can: Run Python Scripts in the RStudio IDE. Use R and Python in a single project with the reticulate Package. Use your Python editor of choice within RStudio tools.

Is R Shiny a programming language?

Shiny is a powerful R package which allows you to create interactive web applications using the R programming language. It is particularly useful for creating applications that run on data and include some sort of data analysis or visualization.

What can R Shiny do?

What is Shiny (R)? Shiny is an R package that enables building interactive web applications that can execute R code on the backend. With Shiny, you can host standalone applications on a webpage, embed interactive charts in R Markdown documents, or build dashboards.

Is R Shiny difficult?

Along with Shiny elements, you can use HTML elements to stylize your content in your application. In my opinion, R Shiny is very easy to learn despite how powerful the tool is. If you're working on a side project or looking to add something to your portfolio, I highly recommend trying it out.


2 Answers

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)
like image 65
Alex Yahiaoui Martinez Avatar answered Nov 15 '22 12:11

Alex Yahiaoui Martinez


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))
like image 45
Ramnath Avatar answered Nov 15 '22 14:11

Ramnath