我有个关于闪亮的问题。我将在开场白中说,我确实花了时间在谷歌和其他档案馆里,尝试了一些东西,但还是遗漏了一些东西。我会对任何张贴的失礼表示歉意,并对任何指导表示感谢。
我正在尝试我认为是一个非常基本的任务,以便学习闪亮的代码,从一个闪亮的画廊例子。我将csv文件读取到dataframe (df.shiny)中。我希望选择与一个工具(df.shiny$Facility级别)相关的业务性能数据( df.shiny$Facility),并将其显示在SPC图表中(使用qcc)。
我的问题似乎与将来自server.R的数据提供给ui.R有关。我相信数据会被读取到dataframe中(它在控制台中打印),但ui.R无法使用。我确信我只是忽略了一些东西,但还没有弄清楚。
我使用的是闪亮站点上的文件夹结构,其中server.R和ui.R位于工作目录子文件夹(“闪亮-App-1”),子文件夹中的数据位于该文件夹(闪亮-App-1/ data )。
我插入的帮助跟踪错误的代码通过在控制台中打印SRV-2和UI-1来运行。火狐打开。那就是错误。
options(browser = "C:/Program Files (x86)/Mozilla Firefox/firefox.exe")
library(shiny)
runApp("Shiny-App-1")服务器.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 发布于 2014-05-23 18:02:56
问题是您在ui.R文件中使用的是ui.R,而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') )
))发布于 2016-02-24 22:02:07
或者,您可以将需要由server.R和ui.R访问的所有R对象放在global.R文件中。
更多信息:http://shiny.rstudio.com/articles/scoping.html#global-objects
https://stackoverflow.com/questions/23833631
复制相似问题