How to call Python function from R reticulate in Rmarkdown

I have this Rmarkdown, with a python function:

---
title: "An hybrid experiment"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
runtime: shiny
---

    ```{r setup, include=FALSE}
    library(flexdashboard)
    library(reticulate)
    ```

    ```{python}
    def addTwo(number):
      return number + 2
    ```

And I try to use the function addTwo in a reactive context, so I tried this:

    ```{r}
    renderText({
      the_number <- py$addTwo(input$selector)
      paste0("The text is: ",the_number)
    })
    ```

But I got this error:

TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

Detailed traceback:
  File "<string>", line 2, in addTwo

I must be doing something wrong, please could you guide me to solve this problem?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.