I am trying to create a dynamic construct that takes a large list of expressions and allows the user to interactively select any number of entries for further manipulation. This is what I have envisioned so far:
Construct[largeListOfEntries_] := DynamicModule[{loadButton, viewPane, testlabels,
valuesPicked, dsFunction, buttonPressed = False},
loadButton = Button["Load Initial List", buttonPressed = True;
testlabels = largeListOfEntries[[;; , 2]]];
viewPane = Panel[
Pane[
Dynamic@If[buttonPressed != False,
CheckboxBar[Dynamic[valuesPicked],
MapThread[#1 -> #2 &, {Range[Length@testlabels], testlabels}],
Appearance -> "Vertical"],
"Load List..."],
ImageSize -> {500, 340}, ImageSizeAction -> "Scrollable", Scrollbars -> {True, True}],
Style["Sample Pane", 12, Bold, Purple]];
dsFunction = Button["Modify Selected Element",
Print[largeListOfEntries[[valuesPicked, 1]]]];
Column[{loadButton, viewPane, dsFunction}]]
Given a large list such as this:
largeListOfEntries = {#, "label"} & /@ RandomReal[1, 3000]
Construct[largeListOfEntries]
I would then be able to select any number of elements that I want and apply the downstream function to them (for example purposes here the function just prints the value of the selected element).
Everything appears to be working but for large lists simply the act of clicking the Checkbox
takes a really long time.
I suspect this is due to the fact that DynamicModule
stores all the values at the FrontEnd
and with large lists it can get really slow. If i simply use Module
or keep the everything global then the process is significantly faster but I need to localize my variables and from what I've read using Module
with Dynamic
objects is not recommended and my Dynamic
variables become red indicating conflict.
Is there something that I'm fundamentally doing wrong that is having such a drastic impact on performance?
EDIT (03.18.14)
As Kuba pointed out it is possible to see the hit in performance simply by using:
largeListOfEntries = RandomReal[1, 3000];
CheckboxBar[Dynamic@valuesPicked,largeListOfEntries]
Indicating that the issue may be directly associated with Dynamic
variables in CheckboxBar
. However if that construct is then wrapped with a DynamicModule
, the performance hit is even worse than before, so the Module
itself is also contributing.