How to execute user input characters as code in shiny?

I am creating an application in shiny.

I learned that there is a feature that allows users to enter their own information freely.

It take input from the user as text, don't it?

How can I get users to write and execute the code themselves?

Here is an example
Let's say the following is code that works normally
I will also make it easy for user to change places at will.

iris %>%
"change places"
  plot()

If a user sees this diagram and wants to filter it, they can enter the following

"filter(Sepal.Length > 3) %>%"

Here is the code that runs on shiny when it receives the user's double quotation marks

iris %>%
  filter(Sepal.Length > 3) %>%
  plot()

How can I make this ?
thank you

here is one way.

library(rlang)
library(glue)
my_expression_1 <-   "filter(Sepal.Length > 3) %>%"
(my_query <- glue("iris %>%
 {my_expression_1}  
  plot()"))
(my_expression_2 <-   rlang::parse_expr(my_query))

eval(my_expression_2)
1 Like

This topic was automatically closed 54 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.