如何在使用reactiveFileReader函数时向数据帧添加函数
我使用reactiveFileReader自动更新wd中的数据。但是,我需要在原始数据中添加一些函数,使其可以使用如何在使用reactiveFileReader函数时向数据帧添加函数,r,shiny,shinydashboard,R,Shiny,Shinydashboard,我使用reactiveFileReader自动更新wd中的数据。但是,我需要在原始数据中添加一些函数,使其可以使用 fileData<-reactiveFileReader(intervalMillis = 1000, session = session, filePath = "data.xlsx", readFunc = re
fileData<-reactiveFileReader(intervalMillis = 1000,
session = session,
filePath = "data.xlsx",
readFunc = read_excel)
output$data <- renderTable({
fileData()
})
I want to add somefunction like this
fileData<-fileData %>%
select(-2,-4:-6)
names(fileData)[3:4]<-c("overall","city")
fileData$city<-as.character(fileData$city)
fileData这就是我的想法
library(shiny)
library(dplyr)
# test file (to replace the file you are monitoring)
write.csv(iris, file="iris.csv")
# function you want applied to your data
# this can be defined here, in global.R (if you have that) or inside the server function
process_data <- function(data_from_file) {
result <- data_from_file %>%
select(Species, starts_with("Sepal")) %>%
group_by(Species) %>% summarise_all("mean") %>%
rename(mean_sepal_width="Sepal.Width", mean_sepal_length="Sepal.Length")
return(result)
}
# the user interface, with the first few rows of the original data
# and the data processed by the function
ui <- basicPage(
h3("original data"),
tableOutput("original_data"),
tags$hr(),
h3("processed data"),
tableOutput("processed_data")
)
server <- function(input, output, session) {
fileData<-reactiveFileReader(intervalMillis = 1000,
session = session,
filePath = "iris.csv",
readFunc = read.csv)
output$original_data <- renderTable({
fileData() %>% head
})
# custom function applied to your data
output$processed_data <- renderTable({
process_data( data_from_file = fileData() )
})
}
shinyApp(ui, server)
库(闪亮)
图书馆(dplyr)
#测试文件(替换正在监视的文件)
write.csv(iris,file=“iris.csv”)
#要应用于数据的函数
#这可以在这里定义,在global.R中(如果有)或在服务器函数中定义
处理数据%
按(物种)分组%>%汇总所有(“平均值”)%>%
重命名(平均萼片宽度=“萼片宽度”,平均萼片长度=“萼片长度”)
返回(结果)
}
#用户界面,包含原始数据的前几行
#以及函数所处理的数据
ui这就是我的想法
library(shiny)
library(dplyr)
# test file (to replace the file you are monitoring)
write.csv(iris, file="iris.csv")
# function you want applied to your data
# this can be defined here, in global.R (if you have that) or inside the server function
process_data <- function(data_from_file) {
result <- data_from_file %>%
select(Species, starts_with("Sepal")) %>%
group_by(Species) %>% summarise_all("mean") %>%
rename(mean_sepal_width="Sepal.Width", mean_sepal_length="Sepal.Length")
return(result)
}
# the user interface, with the first few rows of the original data
# and the data processed by the function
ui <- basicPage(
h3("original data"),
tableOutput("original_data"),
tags$hr(),
h3("processed data"),
tableOutput("processed_data")
)
server <- function(input, output, session) {
fileData<-reactiveFileReader(intervalMillis = 1000,
session = session,
filePath = "iris.csv",
readFunc = read.csv)
output$original_data <- renderTable({
fileData() %>% head
})
# custom function applied to your data
output$processed_data <- renderTable({
process_data( data_from_file = fileData() )
})
}
shinyApp(ui, server)
库(闪亮)
图书馆(dplyr)
#测试文件(替换正在监视的文件)
write.csv(iris,file=“iris.csv”)
#要应用于数据的函数
#这可以在这里定义,在global.R中(如果有)或在服务器函数中定义
处理数据%
按(物种)分组%>%汇总所有(“平均值”)%>%
重命名(平均萼片宽度=“萼片宽度”,平均萼片长度=“萼片长度”)
返回(结果)
}
#用户界面,包含原始数据的前几行
#以及函数所处理的数据
ui您可以创建要应用于数据的函数(例如fun
),然后用output$data替换您的renderable
调用。您可以更具体一点吗,您有什么例子吗@Teofileou可以创建要应用于数据的函数(比如fun
),然后用output$data替换renderable
调用。您可以更具体一点,您有什么例子吗@泰奥菲尔