首页 > 解决方案 > 在 rshiny 中调用 python 代码来构建简单的界面

问题描述

我有一个特定的python代码(下面共享)来显示用户输入的类似描述(验证数据)到历史信息。现在由于某种原因,我想使用 Rshiny 创建一个简单的界面,它需要两个字段,例如:

Enter the description:

Enter the region:

And gives me the similar text 

使用的代码是:

new_description='EDAP Scenario is'

from difflib import SequenceMatcher

def similar(a, b):
    return SequenceMatcher(None, a, b).ratio()

description_list=train_data['description'].unique().tolist()
##train_data has historical descriptions
similar_description=[]
for description in description_list:
    result=similar(new_description, description)
    if result >=0.8:
        similar_CR.append(cr)

这里我明确输入的 new_description 需要从界面中获取。

我是 R/Rshiny 的新手。任何帮助/起点将不胜感激

标签: pythonrshiny

解决方案


这是您的应用程序的骨架。

library(shiny)
ui <- basicPage(
  textInput("description", label = "Enter the Description:"),
  textInput("region", label = "Enter the Region:"),
  verbatimTextOutput("txtoutput")
)

server <- function(input, output) {
  output$txtoutput <- renderPrint({
    print(paste("description: ", input$description, "and region: ", input$region))
  })
}
shinyApp(ui, server)

我不确切知道你想如何将 R/shiny 与 python 结合起来,以及“描述”和“区域”的输入在哪里/如何在 python 代码中使用。无论如何,您可能想看看这个包 - rPython。或者你进一步解释,你到底想要达到什么目的。


推荐阅读