我是个新手。我在r中已经有一个数据集,我想在没有read.csv函数的shiny中使用它,因为该数据来自谷歌分析,我已经修改了该数据
我应该把从ga获取数据的代码和修改后的代码放在哪里?
在UI或服务器部件中
以下是数据准备的代码
query.list <- Init(start.date = "2019-10-29",
end.date = "2019-10-30",
dimensions = c("ga:dimension1","ga:dimension116"),
metrics = c("ga:sessions"),
max.results = 60000,
sort = "ga:sessions",
filters="ga:eventAction!=User Location Error",
table.id = "ga:xxxxxxxxx")
ga.query <- QueryBuilder(query.list)
ga.data <- GetReportData(ga.query, token)
ga.data$col<-strsplit(ga.data$dimension116, "\\|")
x<-ga.data
y<- do.call(rbind, x$col)
#colnames(x) <- LETTERS[1:ncol(x)]
colnames(y)[3]<-"Plus_COde"
colnames(y)[2]<-"Long"
colnames(y)[1]<-"Lat"
df<-cbind(x[c("dimension1","sessions")], y)
#df<- data.frame(do.call('rbind', strsplit(as.character(ga.data$dimension116),'|',fixed=TRUE)))
library(revgeo)
library(ggmap)
af<-df[1:100,]
library(varhandle)
af$Lat <- unfactor(af$Lat)
af$Long <- unfactor(af$Long)
for( i in 1:nrow(af) ) {
af$address[i] <- revgeocode(as.numeric(af[i, c("Long","Lat")]), output = "address" )
}这是名为dt的输出数据集
ID Latitude Longitude Address Date
1 311175 10.77294 79.13641 306/65, Parisutham Nagar 30/10/2019
2 292058 12.97354 77.71762 EPIP Zone, Whitefield, Bengaluru 28/10/2019
3 12979 13.04037 80.19383 Sector 11, K. K. Nagar 29/10/2019我想要一个日期范围,我在ui中使用,我想要文本,我可以通过它来搜索一些数据。然而,数据不会被加载到shiny中
ui.r
ui <- fluidPage(
titlePanel("Lat Long App"),
fluidRow(
column(3,
dateRangeInput("dates", h3("Date range")))),
fluidRow(
column(3,
textInput("text", h3("Text input"),
value = "Enter text..."))
),
tableOutput('dt')
)server.r
server <- function(input, output) {
tableOutput('dt')
}
shinyApp(ui, server)我看不到任何加载的数据
发布于 2019-11-02 02:03:54
有几种方法可以做到这一点,但最初,只需将整个数据准备放在服务器中即可。此外,您的服务器表也不正确。您需要一个具有在UI中引用的输出的renderDataTable。
有关更多信息,请查看此链接:https://shiny.rstudio.com/reference/shiny/0.14/renderDataTable.html
由于您是R和构建应用程序的新手,因此在线查找一些教程可能会有所帮助。这里有一个很好的例子,可以让您开始了解一切是如何组合在一起的:https://shiny.rstudio.com/articles/build.html
library(revgeo)
library(ggmap)
library(varhandle)
library(shiny)
ui <- fluidPage(
titlePanel("Lat Long App"),
fluidRow(
column(3,
dateRangeInput("dates", h3("Date range")))),
fluidRow(
column(3,
textInput("text", h3("Text input"),
value = "Enter text..."))
),
tableOutput('dt')
)
server <- function(input, output) {
query.list <- Init(start.date = "2019-10-29",
end.date = "2019-10-30",
dimensions = c("ga:dimension1","ga:dimension116"),
metrics = c("ga:sessions"),
max.results = 60000,
sort = "ga:sessions",
filters="ga:eventAction!=User Location Error",
table.id = "ga:xxxxxxxxx")
ga.query <- QueryBuilder(query.list)
ga.data <- GetReportData(ga.query, token)
ga.data$col<-strsplit(ga.data$dimension116, "\\|")
x<-ga.data
y<- do.call(rbind, x$col)
#colnames(x) <- LETTERS[1:ncol(x)]
colnames(y)[3]<-"Plus_COde"
colnames(y)[2]<-"Long"
colnames(y)[1]<-"Lat"
df<-cbind(x[c("dimension1","sessions")], y)
#df<- data.frame(do.call('rbind', strsplit(as.character(ga.data$dimension116),'|',fixed=TRUE)))
af<-df[1:100,]
af$Lat <- unfactor(af$Lat)
af$Long <- unfactor(af$Long)
for( i in 1:nrow(af) ) {
af$address[i] <- revgeocode(as.numeric(af[i, c("Long","Lat")]), output = "address" )
}
output$dt <- renderDataTable(af)
}
shinyApp(ui, server)https://stackoverflow.com/questions/58662539
复制相似问题