【问题标题】:Is it possible to run a python script in R shiny是否可以在 R Shiny 中运行 python 脚本
【发布时间】:2014-09-14 01:53:35
【问题描述】:

我有一些格式奇怪的数据集,并编写了一些 python 脚本以转换为 csv 格式以在 R 中使用。是否可以在 R 闪亮的应用程序中调用 python 脚本?

【问题讨论】:

  • 我认为答案是肯定的。您可以使用 system 运行 python 脚本。或者,您可以使用 rpy2 在 python 和 R 会话中持久保存值。

标签: python r shiny


【解决方案1】:

这是一个使用rPython 执行python 调用的最小Shiny 应用程序。

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))

【讨论】:

  • 谢谢!你知道是否有安装 R 3.1.0 的方法吗?
  • 在您将应用程序在线发布到 shinyapps.io 后,这会起作用吗?在此处查看相关问题:stackoverflow.com/questions/32829995/…
【解决方案2】:

我知道这个话题已经结束了,但现在你可以使用 python 使用 reticulate 制作 shinyApp。

这是一个极简主义的例子。

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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-19
    • 1970-01-01
    • 2019-09-03
    • 2019-07-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-21
    相关资源
    最近更新 更多