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)
```
```{r}
selectInput("selector",label = "Selector",
choices = list("1" = 1, "2" = 2, "3" = 3),
selected = 1)
```
```{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?
The reticulate
part is fine, and the error actually comes from shiny
.
Here are a few important details regarding input$selector
:
selectInput
as.numeric
req(input$selector)
will avoid an error in renderText
This works:
---
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
```
```{r}
selectInput("selector",label = "Selector",
choices = list("choose 1" = 1, "choose 2" = 2, "choose 3" = 3),
selected = 1)
renderText({
the_number <- py$addTwo(as.numeric(input$selector))
paste0("The text is: ",the_number)
})
```
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With