Вы можете сделать что-то вроде этого:
eval(parse(text = input$code))
Вы можете использовать eval
и parse
для оценки строки.
library(shiny)
library(tidyverse)
library(shinyalert)
ui <- fluidPage( fluidRow(id="form-row",column(6,offset =3 ,id="form-col",p(id="mandatory","'*' Fields are manadatory"),div(id = "form",
div(id="p-container",p(id="form-header","Your Question")),
div(id="form-field-container",
textInput("title", "*Title", width='100%',placeholder="Your Title is here..."),
# verbatimTextOutput("value"),
textOutput("title_val"),
#for text area width 100%
tags$style(HTML(".shiny-input-container:not(.shiny-input-container-inline){width: 100%;}")),
textAreaInput("description", "*Description", width='100%',rows = 3, resize = "both",placeholder="Description..."),
textOutput("desc_val"),
textAreaInput("code", "*Code", width='100%',rows = 3, resize = "both",placeholder="Write your code..."),
textOutput("code_val"),
useShinyalert(),
actionButton("submit", "Submit", class = "btn-primary")
))
)
)
)
server <- function(input, output, session){
model <- reactive({
data <- mtcars # use your own data, might it be in a fileinput or some other data
result <- eval(parse(text = input$code)) # Should include a hint to what way your dataframe is called and how it looks.
result
})
observeEvent( input$submit,{
title_val <- as.character(input$title)
desc_val <- as.character(input$description)
code_val <- as.character(input$code)
ques<- paste(desc_val, code_val,sep=" \n")
shinyalert( title_val, ques, type = "success")
})
}
shinyApp(ui=ui, server=server)
Но, честно говоря, мне не нравится идея разбирать и оценивать текст из пользовательского ввода. Слишком много возможностей, чтобы столкнуться с неприятностями.
Главное преимущество в том, что тот, кто не знаком с R, исчезает, когда мне приходится копировать и вставлять скрипт в качестве ввода