R shiny-ui.R似乎无法识别服务器读取的数据帧。R [英] R Shiny - ui.R seems to not recognize a dataframe read by server.R

查看:6
本文介绍了R shiny-ui.R似乎无法识别服务器读取的数据帧。R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于闪亮的问题。我会在开场白中说,我确实花了很多时间在谷歌等档案馆,尝试了一些东西,但还是错过了一些东西。我将对任何发帖失礼表示歉意,并对任何指导提前表示感谢。

我正在尝试我认为是非常基本的任务,以便从一个闪亮的图库示例中学习闪亮的、改编的代码。我将CSV文件读入数据帧(df.shiny)。我想选择与一个设施(级别为df.shiny$Facility)相关的业务绩效数据(ITBpct),并将其显示在SPC图表中(使用QCC)。

我的问题似乎与将server.R中的数据提供给ui.R有关。我相信数据已读入数据帧(在控制台中打印),但ui.R不可用。我确信我只是忽略了一些东西,但还没有弄清楚。

我使用的是SHINY站点上标注的文件夹结构,server.R和ui.R位于工作目录子文件夹("SHINY-App-1"),子文件夹中的数据位于此文件夹(SHINY-App-1/Data)。

我插入的帮助跟踪错误的代码在控制台中通过打印SRV-2UI-1运行。Firefox打开。然后是错误。

options(browser = "C:/Program Files (x86)/Mozilla Firefox/firefox.exe")
library(shiny)
runApp("Shiny-App-1")

server.R代码

library(shiny)
library(qcc)
print("SRV-1")  # for debugging

df.shiny = read.csv("data/ITBDATA.csv")
print(df.shiny) # for debugging
print("SRV-2")  # for debugging


shinyServer(function(input, output, session) {
    # Combine the selected variables into a new data frame
    # assign xrow <- Facility

    print("SRV-3")  # for debugging
    selectedData <- reactive({  subset(df.shiny, Facility %in% input$xrow)  })
    print("SRV-4")  # for debugging

    output$plot1 <- renderPlot({  qcc(selectedData$ITBpct, type = 'xbar.one')  })
})

ui.R代码

library(shiny)
print("UI-1")  # for debugging

shinyUI(pageWithSidebar(
    headerPanel('SPC Chart by Facility'),
    sidebarPanel( selectInput('xrow', 'Facility', levels(df.shiny$Facility) ) ),
    mainPanel( plotOutput('plot1') )

))

错误消息

ERROR: object 'df.shiny' not found

我可以提供数据。(不确定如何将样本附加到此便笺。)

会话信息

> sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] splines   stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] plyr_1.8.1       forecast_5.4     timeDate_3010.98 zoo_1.7-11       doBy_4.5-10     
 [6] MASS_7.3-31      survival_2.37-7  gplots_2.13.0    car_2.0-20       ggplot2_0.9.3.1 
[11] lattice_0.20-29  qcc_2.3          shiny_0.9.1 

推荐答案

问题是您正在ui.R文件中使用df.shiny$Facility,而df.shiny没有在文件中定义。ui无法查看server中的所有变量,它们有其他通信方式。

要使其正常工作,您需要在服务器上构建selectInput,然后在UI中呈现它。在您的服务器中,添加

shinyServer(function(input, output, session) {
    output$facilityControl <- renderUI({
        facilities <- levels(df.shiny$Facility)
        selectInput('xrow', 'Facility', facilities )
    })

    selectedData <- reactive({  subset(df.shiny, Facility %in% input$xrow)  })
    output$plot1 <- renderPlot({  qcc(selectedData$ITBpct, type = 'xbar.one')  })
})

然后将UI更改为

shinyUI(pageWithSidebar(
    headerPanel('SPC Chart by Facility'),
    sidebarPanel( uiOutput("facilityControl" ),
    mainPanel( plotOutput('plot1') )    
))

这篇关于R shiny-ui.R似乎无法识别服务器读取的数据帧。R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆