使用validate检查reactiveValue是否存在--未找到
我有一个闪亮的代码,如下所示。我需要将变量定义为可更新的reactiveValues(或者我可以将它们定义为全局变量,但是我必须从Rstudio中按clean objects,这对用户来说不是很友好)。我尝试运行验证代码来检查我定义为reactiveValues的数据是否存在。验证(需要(存在(“GSEmRNA$d”),message=“Dataframe not found”)生成“Dataframe not found”,因此,不会绘制我的方框图。如果我将它们定义为全局变量而忘记按clean对象,代码可能会混淆,因为旧数据可以像新数据一样传递。感谢您的帮助 服务器.R使用validate检查reactiveValue是否存在--未找到,r,shiny,R,Shiny,我有一个闪亮的代码,如下所示。我需要将变量定义为可更新的reactiveValues(或者我可以将它们定义为全局变量,但是我必须从Rstudio中按clean objects,这对用户来说不是很友好)。我尝试运行验证代码来检查我定义为reactiveValues的数据是否存在。验证(需要(存在(“GSEmRNA$d”),message=“Dataframe not found”)生成“Dataframe not found”,因此,不会绘制我的方框图。如果我将它们定义为全局变量而忘记按clean
shinyServer(function(input, output) {
observeEvent(input$GoButton,{
dataset <- data.frame(first= c(1,5,9),second=c(8,5,13), third=c(10,3,17))
GSEmRNA <- reactiveValues(d=dataset)
})
output$BoxplotDataset <- renderPlot({
if (input$GoButton== 0) {return()}
else{
validate(need(exists("GSEmRNA$d"),message="Dataframe not found"))
boxplot(GSEmRNA$d)}
})
})
为了记录在案,我还将这个问题发布到了闪亮的谷歌讨论小组这里是更新的代码。要点是:
library(shiny)
server <-shinyServer(function(input, output) {
GSEmRNA <- reactiveValues(d=NULL) #define it ouside
observeEvent(input$GoButton,{
dataset <- data.frame(first= c(1,5,9),second=c(8,5,13), third=c(10,3,17))
GSEmRNA$d <- dataset #assign it inside
})
output$BoxplotDataset <- renderPlot({
validate(need(GSEmRNA$d,"Dataframe not found")) # changed as well
boxplot(GSEmRNA$d)
})
})
ui <- pageWithSidebar(
headerPanel("Dataset Selection"),
sidebarPanel(
actionButton("GoButton","GO")
),
mainPanel(
wellPanel(
column(8, plotOutput("BoxplotDataset")
)
)
))
runApp(list(ui=ui,server=server))
库(闪亮)
服务器
library(shiny)
server <-shinyServer(function(input, output) {
GSEmRNA <- reactiveValues(d=NULL) #define it ouside
observeEvent(input$GoButton,{
dataset <- data.frame(first= c(1,5,9),second=c(8,5,13), third=c(10,3,17))
GSEmRNA$d <- dataset #assign it inside
})
output$BoxplotDataset <- renderPlot({
validate(need(GSEmRNA$d,"Dataframe not found")) # changed as well
boxplot(GSEmRNA$d)
})
})
ui <- pageWithSidebar(
headerPanel("Dataset Selection"),
sidebarPanel(
actionButton("GoButton","GO")
),
mainPanel(
wellPanel(
column(8, plotOutput("BoxplotDataset")
)
)
))
runApp(list(ui=ui,server=server))