我正在尝试获取由模块返回的电抗值并将其填充在另一个模块的另一个电抗值中,问题是电抗值返回空值。
我已经尝试使用browser()函数调试自己。我试图更改返回的变量的名称(该值称为ana)。
library(shiny)
library(data.table)
library(dbscan)
library(Rtsne)
box_dbscan_ui1 <- function(id) {
ns <- NS(id)
tagList(
column(3, numericInput(ns("epsillon"), "Epsillon", 0.5, min = 0, step = 0.1)),
column(9, sliderInput(ns("minPts"), "MinPts", min = 1, max = 20, step = 1, value = 5)),
verbatimTextOutput(ns("result"))
)
}
box_tsne_ui1 <- function(id) {
ns <- NS(id)
tagList(
h4("DBSCAN"),
box_dbscan_ui1(ns("dbscan")),
br(),
column(12, plotOutput(ns("plot")))
)
}
ui <- fluidRow(
box_tsne_ui1("tSNE"),
actionButton("but", "data regeneration")
)
tSNE_box_server1 <- function(input, output, session, data) {
ana <- reactiveValues()
observeEvent({
data()
}, {
ana$tsne <- Rtsne(data(), pca = F, normalize = F, max_iter = 1000, theta = 0)
ana$tsne$Y <- as.data.table(ana$tsne$Y)
},
ignoreInit = T
)
# if there the pca change or the input sphere radius (if it not NA)
observeEvent(ana$tsne, {
if (!is.null(ana$tsne)) {
ana$dbscan <- callModule(DBSCAN_box_server1, "dbscan", reactive(ana$tsne$Y))$dbscan
print(is.null(ana$dbscan))
} else {
ana$dbscan
}
})
observeEvent({
ana$dbscan
}, {
if (is.null(ana$dbscan)) {
ana$plot <- NULL
output$plot <- renderPlot(plot(1, 1))
} else {
# make the plot
output$plot <- renderPlot({
plot(ana$tsne$Y, col = ana$dbscan$cluster)
})
# Render the text
output$outliers <- renderText(print(sum(ana$dbscan$cluster == 0)))
}
}, ignoreInit = T, ignoreNULL = F)
return(ana)
}
DBSCAN_box_server1 <- function(input, output, session, data) {
anadb <- reactiveValues()
observe({
anadb$dbscan <- dbscan(data(), input$epsillon, input$minPts)
output$result <- renderPrint(anadb$dbscan)
})
return(anadb)
}
server <- function(input, output, session) {
session$onSessionEnded(function() {
stopApp()
})
mat_res <- reactiveVal(matrix(rnorm(1000), ncol = 10))
observeEvent(input$but, {
mat_res(matrix(rnorm(1000), ncol = 10))
})
tSNE <- callModule(tSNE_box_server1, "tSNE", mat_res)
observe(print(is.null(tSNE$tsne)))
}
shinyApp(ui, server)
预期结果是print(is.null(ana $ dbscan))响应为FALSE,而不是像我现在那样为TRUE。当我尝试使用对象callModule(DBSCAN_box_server1,“ dbscan”,react(ana $ tsne $ Y))并打印reactValueToList时,它返回一个列表null。
我不知道该怎么办,尤其是因为服务器功能中的值tSNE $ tsne不为空。请帮助我。