我有ui.R,server.R,global.R在闪亮的应用程序中。
当我选择dataset并按actionButton时,我想使用一个反应性全局变量。
示例:
ui.R
fluidPage(
titlePanel("Using global variable"),
fluidRow(
uiOutput("ui1"),
uiOutput("ui2"),
uiOutput("ui3")
),
)
)server.R
function(input, output) {
output$ui1 <- renderUI({
selectInput("dataset", "firstValue", choices = c("first", "second", "third")
})
output$ui2 <- renderUI({
actionButton("doIt", class="btn-primary", "change")
})
output$ui3 <- renderText({
paste(catPath)
})
}global.R
catPath <<- paste(output$dataset, "/completed", sep="")结果是first/completed on ui3 renderText,当我在dataset中选择first时。然后按actionButton键。
我怎样才能完成这个过程?
发布于 2017-02-27 14:12:45
我同意@JohnPaul和@Lee88 88,您的catPath可能属于server.R。话虽如此,我将把它暂时保存在这里(假设您在MWE中有其他原因)。
global.R
catPath <- ""为了以后可以引用,我需要将它设置为某个值,否则这里使用的值应该是毫无意义的(尽管如果不采取任何行动,它将被返回)。
ui.R
我加了一个“停?”操作按钮,这样您就可以“退出”应用程序,并将catPath的值捕获到调用环境中。如果您不打算有意退出应用程序,则不需要。
fluidPage(
titlePanel("Using global variable"),
fluidRow(
uiOutput("ui1"),
uiOutput("ui2"),
uiOutput("ui3"),
actionButton("stopme", "Stop?")
)
)server.R
我更改了output$ui3以创建HTML (不执行计算),然后观察两个事件并对它们进行操作。再说一遍,如果你不需要“停?”按钮上方,您可能不需要第二个观察这里。(如果您确实使用了它,请注意,stopApp的参数将无形地返回给调用方。)
function(input, output, session) {
output$ui1 <- renderUI({
selectInput("dataset", "firstValue", choices = c("first", "second", "third"))
})
output$ui2 <- renderUI({
actionButton("doIt", class="btn-primary", "change")
})
output$ui3 <- renderUI({
textInput("myinput", "catPath", "")
})
observeEvent(input$doIt, {
catPath <<- paste(input$dataset, "/completed", sep = "")
updateTextInput(session, inputId = "myinput", value = catPath)
})
observeEvent(input$stopme, { stopApp(catPath); })
}做一些像newCatPath <- runApp("path/to/dir")这样的事情。
https://stackoverflow.com/questions/42487336
复制相似问题