Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
911 views
in Technique[技术] by (71.8m points)

shiny - python datetime conversion in reticulate gives error

I am struggling with the following scenario:

I am making a shiny app and some of the functionalities are written in python. In my shiny app, I have a dateInput with dateP9 identifier and I am using that dateInput as an input in my python code.

This is the chunk of my app:

library(reticulate)
date_PnL = eventReactive(input$goP9,{
    x = paste("'",gsub("-","",input$dateP9),"'",sep="")
    source_python("historical_PnL_for_A_Date.py")
    result = get_Historical_PnL(x)
    result
}) 
renderTable({date_PnL})

and the python function is :

def get_Historical_PnL(day):
    n_days = 62
    level = 0.5
    method = 'hist'
    data = read_position(day)
    
    PnL = get_pnl_hist2(data,day)
    PnL = PnL.iloc[0:62,]
    return PnL

I get the following stack of errors:

Warning: Error in if: argument is of length zero
149: py_to_r.datetime.datetime
147: py_maybe_convert
146: [[.python.builtin.dic
144: source_python
143: eventReactiveHandler [<text>#4]
99: date_PnL
98: renderTable [<text>#9]
97: func
84: origRenderFunc
83: output$out6066c03f277c834d
3: <Anonymous>
1: markdown::run

Any help would be very much appreciated

question from:https://stackoverflow.com/questions/65913357/python-datetime-conversion-in-reticulate-gives-error

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...