python - 在 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 的新手。任何帮助/起点将不胜感激
解决方案
这是您的应用程序的骨架。
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。或者你进一步解释,你到底想要达到什么目的。
推荐阅读
- android - 用 id 编号保存新用户
- c++ - 将 utf-8 小写转换为大写
- kotlin - Optaplanner 约束流 - 如何检查多个资源
- java - 由于被调用方法的返回值,可能在 [...] 中取消引用空指针
- java - 如何使用当前用户的数据填充 recyclerview?
- c - 为什么这个引导加载程序会崩溃?
- function - 为什么1+1=0(按键和功能)
- javafx - CDI 和 JavaFX (javafx-weaver) 集成
- mysql - 为日期时间数据选择 SQL 数据类型(兼容 MySQL 和 MSSQL)
- scala - 在 Ammonite (scala) 中重新导入脚本