我有一个观察事件,我对反应数据进行一些预处理:
observeEvent(input$preprocess_btn,{
req(input$imputation_numeric, input$imputation_categorical)
object_recipe <- recipe(as.formula(paste(input$variables, "~ .")), train_data())
**
preprocessing steps here
**
trained_recipe <- prep(object_recipe, training = train_data())
print(trained_recipe) #This shows the desired output, but on console
train_data_prep(bake(trained_recipe, new_data = train_data()))
test_data_prep(bake(trained_recipe, new_data = test_data()))
})
代码片段上显示的所需输出将是:
── 食谱────────────
── 输入 按角色结果划分的变量数量:1 个预测变量:7
── 训练信息 训练数据包含713个数据点, 148 行不完整。
── 操作 • 袋装树插补:Age、SibSp、Parch、Fare |已训练 • 模式插补:Pclass、Sex、Embarked |受过培训 • 稀疏、不平衡的变量滤波器被删除: |受过培训 • 以:年龄、SibSp、Parch、票价 | 为中心接受过培训 • 缩放比例:年龄、 SibSp、Parch、票价 |经过训练 • 虚拟变量来自:Pclass、Sex、 登船|训练有素
问题是我不知道如何将它传递给 renderPrint,因为这些变量只能在observeEvent 内部调用,并尝试将其存储在reactiveVal 中但找不到成功
将
observeEvent()
的输出存储在 reactiveVals()
中,然后打印出来。当然,您还需要一个 UI 元素。
rvals <- reactiveVals()
observeEvent(input$preprocess_btn, {
...
rvals$trained_recipe <- prep(object_recipe, training = train_data())
...
}
output$textout <- renderPrint({
rvals$trained_recipe
})