How can I create an interactive application that accepts data and and plots it?

2

I have some code in Mathematica which shows a colored plot, where the coloring depends on data values. I would like to make this into an interactive application that accepts two inputs:

  1. data, a list of data points.
  2. PocetDat, an integer parameter.

I know little about CDF, but i don't see how I can get inputs or table inputs from the users. Further, I want the users of the application to only see the inputs and the final plot -- no code.

data = 
  {-0.003, 0.002, 0.008, 0.014, -0.026, -0.036, -0.042, -0.010, -0.000, 
   -0.014, -0.013,  0.048, 0.014, -0.035, -0.023, 0.025, 0.001, -0.002, 
    0.050, 0.053,  0.031, -0.045, 0.003, 0.052, 0.066, -0.040,  0.016, 
   -0.054, -0.040, -0.042, -0.018, -0.034, -0.032, -0.021,  0.008, -0.007};
PocetDat = 912; 
KorelCiara = 2*Sqrt[1/PocetDat]; 
PRange = 1.2*Max[{data, KorelCiara}];
Show[
  DiscretePlot[data[[i]], {i, 1, Length[data]}, 
    ExtentSize -> Full, 
    ColorFunction -> Function[x, If[Abs[data[[x]]] > KorelCiara, Red, Blue]],  
    ColorFunctionScaling -> False], 
 Plot[{KorelCiara, -KorelCiara}, {x, 0, Length[data]}],  
 PlotRange -> {-PRange, PRange}]

Martin Zvolenský

Posted 2013-12-14T22:56:37.087

Reputation: 23

But with .cdf's there are restrictions: you cannot use input fields and cannot read from files. What you can do is to import data from a (publicly accessible) website. This may be the best option. – bill s – 2013-12-15T07:06:12.863

I want to do something like that: http://secretzone.sktipy.sk/data.php Paste in Input some values from Excel .. it transforms to Mathematica table and I can working with this numbers. As user you know nothing what code do - i can count basic sums or else .. and this i like to do with Mathematica - have 1 input, button to start and after user saved some values it compute something.

– Martin Zvolenský – 2013-12-15T09:01:15.240

Answers

2

There are few things here to consider. First of all if you have some plans for future robust application reading out live data from hard drive, say, or arbitrary user input - then consider Mathematica Enterprise Edition where CDF can be more powerful.

But I think your case is very simple. You just need data input from user in the typical Manipulate interface. There are many ways to do this - especially for pure numerical values. But you have to think about convenience for users of the process of data entry. My favorite method is Locator - because it is interactive and editable. Demonstration Project has many examples to offer, you should search there, but 1st consider examples I give below. There are other ways of course. Consider for example a Slider and then 2 buttons to add and delete a point. Slider itself is better than InputField IMHO because it already has input field built-in

enter image description here

BTW apps at Demonstration Project address your other question - they are clearly examples where user sees only interface and not code. It is easy. When you deploy CDF cellect only cell that contains interface, do not select the code cell.

enter image description here

enter image description here

Vitaliy Kaurov

Posted 2013-12-14T22:56:37.087

Reputation: 66 672

Hello, thanks but I don't need Slider. I need to add many values in InputField and counting for example Sum of them. Can you do something with your value 0.208? It is possible to saved more values in 1 input? Can compute Sum of this numeric values? – Martin Zvolenský – 2013-12-15T09:05:54.027

@MartinZvolenský I really recommend looking through the source code of these Demonstrations (and many others at Demonstration project). They obviously deal with data that user inputs and do analysis on them - isn't it what you need? Also it is not clear is user adding data 1-by-1 or many at once? If it is many at once - are you imagining user tediously typing all those decimal digits you showed in your example? Exact details of user action are not clear to me. – Vitaliy Kaurov – 2013-12-15T09:15:31.113

Yes it is what I need, but i nothing found :) – Martin Zvolenský – 2013-12-15T09:22:29.173

Many at once. This values are output from other software. If you have just one example it would be very helpful for me. – Martin Zvolenský – 2013-12-15T09:24:50.373

@MartinZvolenský Why not just import that file from another software with Import command? – Vitaliy Kaurov – 2013-12-15T12:01:12.073

I just do it. But how can it be dynamic? When something changed in file which is imported, CDF file change chart?

I really need some example of that. My code is now: – Martin Zvolenský – 2013-12-15T13:30:42.967

Cesta = NotebookDirectory[] <> "korelogramy.xlsx"; data = Import[Cesta, {"Data", 1}]; PocetDat = data[[1, 2]]; KorelCiara = 2Sqrt[1/PocetDat]; PRange = 1.2Max[{data[[All, 1]], KorelCiara}]; Show[DiscretePlot[data[[i, 1]], {i, 1, Length[data]}, ExtentSize -> Full, ColorFunction -> Function[x, If[Abs[data[[x, 1]]] > KorelCiara, Red, Blue]], ColorFunctionScaling -> False], Plot[{KorelCiara, -KorelCiara}, {x, 0, Length[data]}], PlotRange -> {PRange, -PRange}] – Martin Zvolenský – 2013-12-15T13:31:20.500

It works ok, but i must evaluate cell with this code, and this cell is visible. My desire is to showing plots fully automatic (depends on values in xlsx file) - and only plot will be visible. – Martin Zvolenský – 2013-12-15T13:33:40.450