【发布时间】:2021-09-12 18:55:17
【问题描述】:
我想在 Shiny 应用程序中插入变量的值并从 R 脚本中调用它,但我不知道如何修改脚本(“myscript.R”)以接收变量( “文本”)来自应用程序。
这是我的代码示例:
library(shiny)
library(shinyBS)
source("myscript.R", local = TRUE)
用户界面
ui <- fluidPage(
wellPanel(
fluidRow(
textInput(inputId = "text", label = "Insert your name...", value = ""),
actionButton("runScript", "Run")
),
),
)
服务器
server <- function(input, output, session) {
mylist <- reactiveVal()
observe({
mylist(list(
text = input$text))
})
observeEvent(input$runScript, {
source("myscript.R", local = list2env(mylist()))
})
}
R 脚本
myscript <- function(text)
{
myname <- text
print(myname) # I have simplified my code...The use of the variable "text" is more complex
}
非常感谢您的帮助!
【问题讨论】:
标签: r variables input shiny reactive