R - Shiny App: Read in csv and convert it to a dataframe / ts object
I want to create a Forecast Shiny App. The user should be able to upload a csv or xls file. With the data in the file, the forecast should be done.
Since the file could be another one each time, I created a reactive read in:
data <- reactive ({
file1 <- input$file
if(is.null(file1)){return()}
read.table(file = file1$datapath, sep = input$sep, header = input$header)
})
To be able to further work with the data and create a simple plot, I created a dataframe:
output$plot <- renderPlot ({
#create dataframe
df <- as.data.frame(data())
plot(df)
)}
My input file is a simple csv which only contains one column with pageimpressions. The title of the column also is pageimpressions. Now the df <- as.data.frame(t(data()))
part creates a df which looks like this:
Does anybody know how to create a "normal" dataframe which looks like this:
AND/OR: Does anybody know how to directly create a ts object of the upper dataframe?
Many thanks in advance!
(Used packages: library(shiny))
r dataframe shiny time-series
add a comment |
I want to create a Forecast Shiny App. The user should be able to upload a csv or xls file. With the data in the file, the forecast should be done.
Since the file could be another one each time, I created a reactive read in:
data <- reactive ({
file1 <- input$file
if(is.null(file1)){return()}
read.table(file = file1$datapath, sep = input$sep, header = input$header)
})
To be able to further work with the data and create a simple plot, I created a dataframe:
output$plot <- renderPlot ({
#create dataframe
df <- as.data.frame(data())
plot(df)
)}
My input file is a simple csv which only contains one column with pageimpressions. The title of the column also is pageimpressions. Now the df <- as.data.frame(t(data()))
part creates a df which looks like this:
Does anybody know how to create a "normal" dataframe which looks like this:
AND/OR: Does anybody know how to directly create a ts object of the upper dataframe?
Many thanks in advance!
(Used packages: library(shiny))
r dataframe shiny time-series
add a comment |
I want to create a Forecast Shiny App. The user should be able to upload a csv or xls file. With the data in the file, the forecast should be done.
Since the file could be another one each time, I created a reactive read in:
data <- reactive ({
file1 <- input$file
if(is.null(file1)){return()}
read.table(file = file1$datapath, sep = input$sep, header = input$header)
})
To be able to further work with the data and create a simple plot, I created a dataframe:
output$plot <- renderPlot ({
#create dataframe
df <- as.data.frame(data())
plot(df)
)}
My input file is a simple csv which only contains one column with pageimpressions. The title of the column also is pageimpressions. Now the df <- as.data.frame(t(data()))
part creates a df which looks like this:
Does anybody know how to create a "normal" dataframe which looks like this:
AND/OR: Does anybody know how to directly create a ts object of the upper dataframe?
Many thanks in advance!
(Used packages: library(shiny))
r dataframe shiny time-series
I want to create a Forecast Shiny App. The user should be able to upload a csv or xls file. With the data in the file, the forecast should be done.
Since the file could be another one each time, I created a reactive read in:
data <- reactive ({
file1 <- input$file
if(is.null(file1)){return()}
read.table(file = file1$datapath, sep = input$sep, header = input$header)
})
To be able to further work with the data and create a simple plot, I created a dataframe:
output$plot <- renderPlot ({
#create dataframe
df <- as.data.frame(data())
plot(df)
)}
My input file is a simple csv which only contains one column with pageimpressions. The title of the column also is pageimpressions. Now the df <- as.data.frame(t(data()))
part creates a df which looks like this:
Does anybody know how to create a "normal" dataframe which looks like this:
AND/OR: Does anybody know how to directly create a ts object of the upper dataframe?
Many thanks in advance!
(Used packages: library(shiny))
r dataframe shiny time-series
r dataframe shiny time-series
edited Nov 12 '18 at 16:25
asked Nov 12 '18 at 13:21
nississippi
1039
1039
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
At least for the "normal" dataframe I'm not sure why you're running this line:
df <- as.data.frame(t(data()))
data()
is already the "normal" dataframe once it gets read into R using read.table()/read.csv(). If you run class(data())
you should get [1] "data.frame"
the t()
creates the transpose of the dataframe but it doesn't seem you're after that?
You could try plot.ts()
or ts.plot()
.
For ts the xts
package is quite useful although you need some sort of time corresponding to the data points which I don't see in the dataset above.
Thanks for your comments.You are right. This is a mistake. I corrected my code.
– nississippi
Nov 12 '18 at 16:22
Second: I didnt include any sort of time, because the ts() package normally does it itself. At least I always could use it that way, when not using shiny. I use this code: dailyts<- ts(df, start =c(2018,08,01), frequency = 365)
– nississippi
Nov 12 '18 at 16:28
dailyts<- ts(df, start =c(2018,08,01), frequency = 365) should work with the above code. Or if you have dailyts<- ts(data(), start =c(2018,08,01), frequency = 365) and then plot(dailyts). Sorry, it's a little difficult to fully understand what your issue is.
– Eli Berkow
Nov 13 '18 at 6:48
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53263093%2fr-shiny-app-read-in-csv-and-convert-it-to-a-dataframe-ts-object%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
At least for the "normal" dataframe I'm not sure why you're running this line:
df <- as.data.frame(t(data()))
data()
is already the "normal" dataframe once it gets read into R using read.table()/read.csv(). If you run class(data())
you should get [1] "data.frame"
the t()
creates the transpose of the dataframe but it doesn't seem you're after that?
You could try plot.ts()
or ts.plot()
.
For ts the xts
package is quite useful although you need some sort of time corresponding to the data points which I don't see in the dataset above.
Thanks for your comments.You are right. This is a mistake. I corrected my code.
– nississippi
Nov 12 '18 at 16:22
Second: I didnt include any sort of time, because the ts() package normally does it itself. At least I always could use it that way, when not using shiny. I use this code: dailyts<- ts(df, start =c(2018,08,01), frequency = 365)
– nississippi
Nov 12 '18 at 16:28
dailyts<- ts(df, start =c(2018,08,01), frequency = 365) should work with the above code. Or if you have dailyts<- ts(data(), start =c(2018,08,01), frequency = 365) and then plot(dailyts). Sorry, it's a little difficult to fully understand what your issue is.
– Eli Berkow
Nov 13 '18 at 6:48
add a comment |
At least for the "normal" dataframe I'm not sure why you're running this line:
df <- as.data.frame(t(data()))
data()
is already the "normal" dataframe once it gets read into R using read.table()/read.csv(). If you run class(data())
you should get [1] "data.frame"
the t()
creates the transpose of the dataframe but it doesn't seem you're after that?
You could try plot.ts()
or ts.plot()
.
For ts the xts
package is quite useful although you need some sort of time corresponding to the data points which I don't see in the dataset above.
Thanks for your comments.You are right. This is a mistake. I corrected my code.
– nississippi
Nov 12 '18 at 16:22
Second: I didnt include any sort of time, because the ts() package normally does it itself. At least I always could use it that way, when not using shiny. I use this code: dailyts<- ts(df, start =c(2018,08,01), frequency = 365)
– nississippi
Nov 12 '18 at 16:28
dailyts<- ts(df, start =c(2018,08,01), frequency = 365) should work with the above code. Or if you have dailyts<- ts(data(), start =c(2018,08,01), frequency = 365) and then plot(dailyts). Sorry, it's a little difficult to fully understand what your issue is.
– Eli Berkow
Nov 13 '18 at 6:48
add a comment |
At least for the "normal" dataframe I'm not sure why you're running this line:
df <- as.data.frame(t(data()))
data()
is already the "normal" dataframe once it gets read into R using read.table()/read.csv(). If you run class(data())
you should get [1] "data.frame"
the t()
creates the transpose of the dataframe but it doesn't seem you're after that?
You could try plot.ts()
or ts.plot()
.
For ts the xts
package is quite useful although you need some sort of time corresponding to the data points which I don't see in the dataset above.
At least for the "normal" dataframe I'm not sure why you're running this line:
df <- as.data.frame(t(data()))
data()
is already the "normal" dataframe once it gets read into R using read.table()/read.csv(). If you run class(data())
you should get [1] "data.frame"
the t()
creates the transpose of the dataframe but it doesn't seem you're after that?
You could try plot.ts()
or ts.plot()
.
For ts the xts
package is quite useful although you need some sort of time corresponding to the data points which I don't see in the dataset above.
answered Nov 12 '18 at 15:12
Eli Berkow
46239
46239
Thanks for your comments.You are right. This is a mistake. I corrected my code.
– nississippi
Nov 12 '18 at 16:22
Second: I didnt include any sort of time, because the ts() package normally does it itself. At least I always could use it that way, when not using shiny. I use this code: dailyts<- ts(df, start =c(2018,08,01), frequency = 365)
– nississippi
Nov 12 '18 at 16:28
dailyts<- ts(df, start =c(2018,08,01), frequency = 365) should work with the above code. Or if you have dailyts<- ts(data(), start =c(2018,08,01), frequency = 365) and then plot(dailyts). Sorry, it's a little difficult to fully understand what your issue is.
– Eli Berkow
Nov 13 '18 at 6:48
add a comment |
Thanks for your comments.You are right. This is a mistake. I corrected my code.
– nississippi
Nov 12 '18 at 16:22
Second: I didnt include any sort of time, because the ts() package normally does it itself. At least I always could use it that way, when not using shiny. I use this code: dailyts<- ts(df, start =c(2018,08,01), frequency = 365)
– nississippi
Nov 12 '18 at 16:28
dailyts<- ts(df, start =c(2018,08,01), frequency = 365) should work with the above code. Or if you have dailyts<- ts(data(), start =c(2018,08,01), frequency = 365) and then plot(dailyts). Sorry, it's a little difficult to fully understand what your issue is.
– Eli Berkow
Nov 13 '18 at 6:48
Thanks for your comments.You are right. This is a mistake. I corrected my code.
– nississippi
Nov 12 '18 at 16:22
Thanks for your comments.You are right. This is a mistake. I corrected my code.
– nississippi
Nov 12 '18 at 16:22
Second: I didnt include any sort of time, because the ts() package normally does it itself. At least I always could use it that way, when not using shiny. I use this code: dailyts<- ts(df, start =c(2018,08,01), frequency = 365)
– nississippi
Nov 12 '18 at 16:28
Second: I didnt include any sort of time, because the ts() package normally does it itself. At least I always could use it that way, when not using shiny. I use this code: dailyts<- ts(df, start =c(2018,08,01), frequency = 365)
– nississippi
Nov 12 '18 at 16:28
dailyts<- ts(df, start =c(2018,08,01), frequency = 365) should work with the above code. Or if you have dailyts<- ts(data(), start =c(2018,08,01), frequency = 365) and then plot(dailyts). Sorry, it's a little difficult to fully understand what your issue is.
– Eli Berkow
Nov 13 '18 at 6:48
dailyts<- ts(df, start =c(2018,08,01), frequency = 365) should work with the above code. Or if you have dailyts<- ts(data(), start =c(2018,08,01), frequency = 365) and then plot(dailyts). Sorry, it's a little difficult to fully understand what your issue is.
– Eli Berkow
Nov 13 '18 at 6:48
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53263093%2fr-shiny-app-read-in-csv-and-convert-it-to-a-dataframe-ts-object%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown