我想在反应式表达式中调用某个变量。像这样的东西:
server.R
library(raster)
shinyServer(function(input, output) {
data <- reactive({
inFile <- input$test #Some uploaded ASCII file
asc <- raster(inFile$datapath) #Reads in the ASCII as raster layer
#Some calculations with 'asc':
asc_new1 <- 1/asc
asc_new2 <- asc * 100
})
output$Plot <- renderPlot({
inFile <- input$test
if (is.null(inFile)
return (plot(data()$asc_new1)) #here I want to call asc_new1
plot(data()$asc_new2)) #here I want to call asc_new2
})
})
不幸的是我不知道如何打电话asc_new1
and asc_new2
within data()
。这个不起作用:
data()$asc_new1
Reactives 就像 R 中的其他函数一样。你不能这样做:
f <- function() {
x <- 1
y <- 2
}
f()$x
所以你在里面output$Plot()
也行不通。您可以通过返回列表来执行您想要的操作data()
.
data <- reactive({
inFile <- input$test
asc <- raster(inFile$datapath)
list(asc_new1 = 1/asc, asc_new2 = asc * 100)
})
现在你可以这样做:
data()$asc_new1
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)