Message Boards Message Boards

0
|
3809 Views
|
6 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Can FormPage be used to upload a file?

I want to use FormPage to give the user an option to upload a CSV file and once it is uploaded, the data from the file should be plotted. How can this be done?

Thanks!

6 Replies

Sorry about that. I should have provided more details about the data. I have attached the file now as 'data.csv'. It has one column and the contents need to be plotted as a scatter plot.

I did write a small code to make sure it works logically. This is the code:

k = Transpose[Import["D:/MTU/Mathematica/data.csv"]];
ListPlot[k]

This code works perfectly fine. Now I want to perform the same action with uploading the file instead of importing it.

Thanks! Siddharth

Yes, I completely agree. I want to make it work first before I deploy to the cloud.

Attachments:
Posted 3 years ago

Looks like you asked the plotting question here. Not sure why you chose to ask part of the question on MSE and part of it here.

Anyway, the code I provided in addition to the answer from MSE is enough for you to put together a working solution. Try it.

POSTED BY: Rohit Namjoshi

The post on MSE was before I was able to plot the data using "Import". The two questions are at different stages of the problem. There was no real answer from MSE, I was able to figure that part out myself.

I couldn't really put together a working solution from it, given my inexperience.

Thanks anyways.

Posted 3 years ago

The reason for the Export is to generate a self-contained example for you to experiment with. If you evaluate the code provided and follow the steps, you will see that a plot is generated.

If no plot is generated with your CSV file then it may not be in a form that can directly be plotted. You have provided no details on the format of your CSV file, does it have a header row, how many columns, which columns need to be plotted, are the columns strings that need to be converted to numbers, .....???

Before trying to do anything in the cloud, make sure the code works locally first. What is the result of evaluating

data = Import["path to your file", "CSV"]
POSTED BY: Rohit Namjoshi
Posted 3 years ago

Hi Siddharth,

This should get you started

Export["test.csv", Table[N@{x, Sin[x]}, {x, 0, 2 Pi, Pi/12}], "CSV"];
FormFunction[{"file" -> "CSV"}, ListLinePlot[#file] &]

Click on Browse, select test.csv and then click Submit.

POSTED BY: Rohit Namjoshi
Posted 3 years ago

Hey Rohit,

Thanks.

I am a bit confused, and I apologize for simple questions here, it has just been a week since I started using Mathematica.

I don't need to export any data, so I've just removed the 'Export' function.

The FormFunction allows the file to be uploaded. Once uploaded, is there any way I can visualize the contents of the file on the screen? The plot isn't showing any data right now visualizing the format will probably give me an idea of what needs to be done.

Thanks again! Siddharth

POSTED BY: Updating Name
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract