我正在用Python构建一个
Plotly
Dash,我需要使用rpy2包来导入一些Python不支持的函数,所以当我在dash中调用(%R-i df)
时,会收到此错误,
奇怪的是,R 代码在破折号之外工作得很好,但用它它不能完全实现 R 的任何代码。
我尝试了下面链接的所有解决方案,但它不起作用。有什么想法吗?
https://github.com/theislab/anndata2ri/issues/50 https://rpy2.github.io/doc/latest/html/pandas.html
您需要在 Dash/Plotly 绘图函数中添加 r 上下文 - 具有回调更新的函数。像这样的东西。
@app.callback(
Output('graph-to-update', 'figure'),
Input('input-slide', 'value')
)
def my_graph_func(var):
with localconverter(ro.default_converter + pandas2ri.converter):
result = robject(var)
fig = create_myfigure(result)
return fig
rpy2 文档解释了您的问题:https://rpy2.github.io/doc/latest/html/pandas.html
面临同样的问题。你有没有找到解决这个问题的方法?