r - 加载的数据在服务器功能中不可用
问题描述
我需要帮助我已经看到类似的问题得到了回答,但我就是无法正确回答,这让我发疯了。
所以这是问题所在,当我使用 ctr + a 运行应用程序时,一切都很好,但是当我单击运行应用程序按钮时,出现以下错误
Error in hasGroups(choices) : object 'my_data' not found
另外,如果我只是在单个文件中运行脚本(不是真正可行的原始文件太大)它可以工作这是脚本 代码
library("tidyverse")
library("readxl")
library("writexl")
library("shiny")
write_xlsx(x = iris, path = "app/IRIS.xlsx")
my_data2 <- read_excel(path = "app/IRIS.xlsx")
source("app/pre_process.R")
my_data <- rename(my_data2)
# comment source and uncomment ui and server and it will work fine
source("app/ui.R")
source("app/server.R")
# ui <- pageWithSidebar(
# headerPanel('my_data k-means clustering'),
# sidebarPanel(
# selectInput('xcol', 'X Variable', names(my_data)),
# selectInput('ycol', 'Y Variable', names(my_data),
# selected=names(my_data)[[2]]),
# numericInput('clusters', 'Cluster count', 3,
# min = 1, max = 9)
# ),
# mainPanel(
# plotOutput('plot1')
# )
# )
# server <- function(input, output, session) {
#
# # Combine the selected variables into a new data frame
# selectedData <- reactive({
# my_data %>% select(input$xcol, input$ycol)
# })
#
# clusters <- reactive({
# kmeans(selectedData(), input$clusters)
# })
#
# output$plot1 <- renderPlot({
# palette(c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3",
# "#FF7F00", "#FFFF33", "#A65628", "#F781BF", "#999999"))
#
# par(mar = c(5.1, 4.1, 0, 1))
# plot(selectedData(),
# col = clusters()$cluster,
# pch = 20, cex = 3)
# points(clusters()$centers, pch = 4, cex = 4, lwd = 4)
# })
#
# }
servidor <- server
shinyApp(ui, server)
预处理
rename <- function(my_data) {
names(my_data) <- c("tallo_l", "tallo_w", "petalo_l", "petalo_w", "especie")
return(my_data)
}
这是
Github 存储库
https://github.com/alfonsonoguer/pre-process-app
一般来说,我只是不知道我必须在哪里编写代码才能将其加载到闪亮的环境中。
感谢您的时间和关注,这对您有很大帮助。
解决方案
这是 R 查找 ui 和服务器文件的位置(即在哪个环境中)的问题:
如果您local=TRUE
在采购时添加参数ui.R
,server.R
则应用程序应在使用“运行应用程序”按钮运行时和从脚本以交互方式运行时运行。这相当于将两个文件的内容直接打印到脚本中。
另请参阅此处的解释,特别是“包含的 R 文件的范围”部分。
推荐阅读
- python-3.x - 使用 sqllite3 和 sqllite 脚本处理
- javascript - 更改 new Date() 时间的值
- python - 为什么我的 YouTube 视频下载器只下载一些视频,而对于其他视频,它会显示 URL 和密码等密钥错误?
- spring-boot - org.mockito.exceptions.misusing.InvalidUseOfMatchersException:参数匹配器的使用无效!预计有 2 个匹配者,记录 3 个
- excel - 为什么用 excel 表计算的偏斜值与用 pyspark/scipy 计算的值不同
- angular - 将 scss 变量导入 Angular 组件
- laravel - 直接返回关系(一对多)值而不是其 Id 的最佳方法是什么?
- python - 即使找到了值,遍历字典也返回 None
- mongodb - 当外部字段和本地字段是对象数组时的MongoDB查找
- javascript - 通过 Javascript 插入服务器端呈现的 HTML