I would like my document to have a control looking something like this
I don’t think it is possible but I would love to be told otherwise
It might depend on how faithful to that specific image you want to be. You can use pretty much anything you want for the labels in the popup menu, but you might not be able to get the “feel” of a single grid with its own drop-shadow and other details. So, here is a very loose approximation–maybe you can tweak it to get something close enough:
PopupMenu[
Dynamic[molecule],
{Entity["Chemical", "AceticAcid"] ->
Grid[{{"Acetic acid", 4.74}}, ItemSize -> {{12, 4}, Automatic}, Alignment -> Left],
Entity["Chemical", "BromoaceticAcid"] ->
Grid[{{"Bromoacetic acid", 2.69}}, ItemSize -> {{12, 4}, Automatic}, Alignment -> Left],
Entity["Chemical", "AdipicAcid"] ->
Grid[{{"Adipic acid", 5.41}}, ItemSize -> {{12, 4}, Automatic}, Alignment -> Left]}]
Of course, you probably want to come up with a way to programmatically generate this data.
Thanks - I’ll experiment with that and see how I get on.
I have a database of acids and their dissociation constants which I could presumably import (either from DBF or XLS/XLSX) but how I would then programmatically generate the the data required for PopupMenu might be a problem. Do you have any ideas on that? Could we iterate through the data and add entities to PopupMenu one at a time?
If you have the data in a structured form, then that part of the problem would be easy. If you add some sample data, I can show you how. But you might want to first experiment with the UI side of things. You might decide you want Row instead of Grid (or whatever) and so your function to transform from raw data to a UI-friendly representation will depend on where you land on the UI side of things.
I am not sure how the UI would differ using Row instead of Grid but am attaching sample data and perhaps you could advise.
I will also need to investigate how I can respond to changing the selection in the PopupMenu but that can come later.
Dissociation constants.dbf (17.6 KB)
Dissociation constants.xlsx (17.9 KB)
Here is one way
data = Import[
"~/Downloads/Dissociation constants.xlsx", {"Dataset", 1}] // Normal //
DeleteCases[{"", ""}];
menuData = Grid[{#}, ItemSize -> {{35, 5}, Automatic}, Alignment -> Left, Dividers -> Center] & /@ data;
Manipulate[molecule[[1, 1]], {molecule, menuData}]
The menu entries are wide because some molecule names are very long, so a larger ItemSize width is needed to prevent wrapping.
Looks like Rohit got to it first. You can see the basic idea: create a function that creates the display form for a single “row” of data and map it over your data. You can experiment with Grid, Row, formatted strings, or anything else that strikes your fancy.
Thank you Rohit and Eric. I much prefer the look of PopupMenu (just a personal thing) so I wonder whether we could adapt Rohit’s code to populate PopupMenu?
Hi Paul,
Because there are so many items in menuData they are automatically rendered as a PopupMenu by Manipulate. If you want just a PopupMenu then use the pattern in Eric’s code
PopupMenu[Dynamic@molecule, menuData]
That’s exactly what I wanted - many thanks Rohit