Function Repository Resource:

FormatDataset

Source Notebook

Format a dataset using a given set of option values

Contributed by: Seth J. Chandler

ResourceFunction["FormatDataset"][rule1,]

represents an operator that applies the formatting options rulei to a Dataset.

Details

The arguments can be any options accepted by Dataset.

Examples

Basic Examples (2) 

Apply formatting rules to a Dataset:

In[1]:=
ResourceFunction["FormatDataset"][Background -> Pink][\!\(\*
TagBox[
TagBox[
DynamicModuleBox[{
      TypeSystem`NestedGrid`PackagePrivate`$state$$ = <|"InitialData" -> {<|"a" -> 1, "b" -> "x"|>, <|"a" -> 2, "b" -> "y"|>},
        "AllowEmbedding" -> True, "InitialShape" -> TypeSystem`PackageScope`HeaderShape[<|{All, "a"} -> 1, {All, "b"} -> 1|>, 
TypeSystem`PackageScope`Limited[
TypeSystem`PackageScope`ColumnShape[
TypeSystem`PackageScope`Limited[
TypeSystem`PackageScope`RowShape[<|"a" -> TypeSystem`PackageScope`AtomShape[34], "b" -> TypeSystem`PackageScope`AtomShape[33.6]|>], 
DirectedInfinity[1], 2, {All}]], 2, 
DirectedInfinity[1], {}]], "InitialType" -> TypeSystem`Vector[
TypeSystem`Struct[{"a", "b"}, {
TypeSystem`Atom[Integer], 
TypeSystem`Atom[String]}], 2], "Meta" -> <||>, "RowTarget" -> 20, "ColumnTarget" -> 10, "Shape" -> TypeSystem`PackageScope`HeaderShape[<|{All, "a"} -> 1, {All, "b"} -> 1|>, 
TypeSystem`PackageScope`Limited[
TypeSystem`PackageScope`ColumnShape[
TypeSystem`PackageScope`Limited[
TypeSystem`PackageScope`RowShape[<|"a" -> TypeSystem`PackageScope`AtomShape[34], "b" -> TypeSystem`PackageScope`AtomShape[33.6]|>], 
DirectedInfinity[1], 2, {All}]], 2, 
DirectedInfinity[1], {}]], "Type" -> TypeSystem`Vector[
TypeSystem`Struct[{"a", "b"}, {
TypeSystem`Atom[Integer], 
TypeSystem`Atom[String]}], 2], "Path" -> {}, "DisplayedRowCount" -> 2,
        "DisplayedColumnCount" -> 2, "DataRowCount" -> 2, "DataColumnCount" -> 2, "SortPaths" -> {}, "SortDirections" -> {},
        "HiddenItemsMap" -> Null, "UpdateType" -> 1|>, TypeSystem`NestedGrid`PackagePrivate`$outputID$$, TypeSystem`NestedGrid`PackagePrivate`$path$$ = {}, TypeSystem`NestedGrid`PackagePrivate`$vPos$$ = 1, TypeSystem`NestedGrid`PackagePrivate`$hPos$$ = 1, TypeSystem`NestedGrid`PackagePrivate`$grid$$ = DynamicModule[{TypeSystem`NestedGrid`PackagePrivate`renderedGrid = Deploy[
Style[
Grid[{{
Item[
Pane[
Annotation[
EventHandler[
MouseAppearance[
Mouseover["a", 
Style["a", FontColor -> RGBColor[
                    0.27450980392156865`, 0.5372549019607843, 0.792156862745098]]], "LinkHand"], {"MouseClicked", 1} :> If[
TypeSystem`NestedGrid`PackagePrivate`checkInteractivity[
                    TypeSystem`NestedGrid`PackagePrivate`$state$$], 
TypeSystem`NestedGrid`PackagePrivate`updateState[
                    TypeSystem`NestedGrid`PackagePrivate`$state$$, TypeSystem`NestedGrid`PackagePrivate`$path$$, TypeSystem`NestedGrid`PackagePrivate`$vPos$$, TypeSystem`NestedGrid`PackagePrivate`$hPos$$, TypeSystem`NestedGrid`PackagePrivate`$grid$$, 
TypeSystem`NestedGrid`PackagePrivate`localHold[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]]][{All, "a"}, 1]]], 
TypeSystem`NestedGrid`PackagePrivate`$SliceMarker[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                  "efb45e7e-10f6-433e-9668-713e107dbbf0"]][{All, "a"},
                   "ColumnHeader", True], "Mouse"], ImageSize -> {{1, Full}, Automatic}, ImageMargins -> {{5, 3}, {4, 5}}], Background -> GrayLevel[0.95], Alignment -> {Left, Baseline}], 
Item[
Pane[
Annotation[
EventHandler[
MouseAppearance[
Mouseover["b", 
Style["b", FontColor -> RGBColor[
                    0.27450980392156865`, 0.5372549019607843, 0.792156862745098]]], "LinkHand"], {"MouseClicked", 1} :> If[
TypeSystem`NestedGrid`PackagePrivate`checkInteractivity[
                    TypeSystem`NestedGrid`PackagePrivate`$state$$], 
TypeSystem`NestedGrid`PackagePrivate`updateState[
                    TypeSystem`NestedGrid`PackagePrivate`$state$$, TypeSystem`NestedGrid`PackagePrivate`$path$$, TypeSystem`NestedGrid`PackagePrivate`$vPos$$, TypeSystem`NestedGrid`PackagePrivate`$hPos$$, TypeSystem`NestedGrid`PackagePrivate`$grid$$, 
TypeSystem`NestedGrid`PackagePrivate`localHold[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]]][{All, "b"}, 1]]], 
TypeSystem`NestedGrid`PackagePrivate`$SliceMarker[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                  "efb45e7e-10f6-433e-9668-713e107dbbf0"]][{All, "b"},
                   "ColumnHeader", True], "Mouse"], ImageSize -> {{1, Full}, Automatic}, ImageMargins -> {{5, 3}, {4, 5}}], Background -> GrayLevel[0.95], Alignment -> {Left, Baseline}]}, {
Item[
Pane[
Annotation[
RawBoxes["1"], 
TypeSystem`NestedGrid`PackagePrivate`$SliceMarker[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                  "efb45e7e-10f6-433e-9668-713e107dbbf0"]][{1, 
Key["a"]}, "Item", False], "Mouse"], ImageSize -> {{34, Full}, Automatic}, ImageMargins -> {{5, 3}, {4, 5}}], ItemSize -> {Full, Automatic}], 
Item[
Pane[
Annotation["x", 
TypeSystem`NestedGrid`PackagePrivate`$SliceMarker[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                  "efb45e7e-10f6-433e-9668-713e107dbbf0"]][{1, 
Key["b"]}, "Item", False], "Mouse"], ImageSize -> {{33.6, Full}, Automatic}, ImageMargins -> {{5, 3}, {4, 5}}], ItemSize -> {Full, Automatic}]}, {
Item[
Pane[
Annotation[
RawBoxes["2"], 
TypeSystem`NestedGrid`PackagePrivate`$SliceMarker[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                  "efb45e7e-10f6-433e-9668-713e107dbbf0"]][{2, 
Key["a"]}, "Item", False], "Mouse"], ImageSize -> {{34, Full}, Automatic}, ImageMargins -> {{5, 3}, {4, 5}}], ItemSize -> {Full, Automatic}], 
Item[
Pane[
Annotation["y", 
TypeSystem`NestedGrid`PackagePrivate`$SliceMarker[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                  "efb45e7e-10f6-433e-9668-713e107dbbf0"]][{2, 
Key["b"]}, "Item", False], "Mouse"], ImageSize -> {{33.6, Full}, Automatic}, ImageMargins -> {{5, 3}, {4, 5}}], ItemSize -> {Full, Automatic}]}}, BaseStyle -> {ContextMenu -> Dynamic[
               TypeSystem`NestedGrid`PackagePrivate`$contextMenuTrigger; Which[
                 TypeSystem`NestedGrid`PackagePrivate`$lastOutputID =!= TypeSystem`NestedGrid`PackagePrivate`localHold[ TypeSystem`NestedGrid`PackagePrivate`$outputID$$], {}, TypeSystem`NestedGrid`PackagePrivate`$contextMenuTrigger === TypeSystem`NestedGrid`PackagePrivate`$lastContextMenuTrigger, TypeSystem`NestedGrid`PackagePrivate`$lastContextMenu, True, TypeSystem`NestedGrid`PackagePrivate`$lastContextMenuTrigger = TypeSystem`NestedGrid`PackagePrivate`$contextMenuTrigger; TypeSystem`NestedGrid`PackagePrivate`$lastContextMenu = Block[{TypeSystem`NestedGrid`PackagePrivate`$globalScrollPos = {TypeSystem`NestedGrid`PackagePrivate`$vPos$$, TypeSystem`NestedGrid`PackagePrivate`$hPos$$}}, 
With[{TypeSystem`NestedGrid`PackagePrivate`lastPath$ = TypeSystem`NestedGrid`PackagePrivate`$lastPath, TypeSystem`NestedGrid`PackagePrivate`lastPathType$ = TypeSystem`NestedGrid`PackagePrivate`$lastPathType, TypeSystem`NestedGrid`PackagePrivate`isLeafHeader$ = TypeSystem`NestedGrid`PackagePrivate`$lastPathIsLeafHeader, TypeSystem`NestedGrid`PackagePrivate`headerHidden$ = And[
MatchQ[TypeSystem`NestedGrid`PackagePrivate`$lastPathType, 
Alternatives["RowHeader", "ColumnHeader"]], 
TypeSystem`NestedGrid`PackagePrivate`headerHiddenQ[
                    TypeSystem`NestedGrid`PackagePrivate`$lastPath, TypeSystem`NestedGrid`PackagePrivate`$state$$]], TypeSystem`NestedGrid`PackagePrivate`allHidden$ = TypeSystem`NestedGrid`PackagePrivate`allHiddenQ[
                    TypeSystem`NestedGrid`PackagePrivate`$lastPath, TypeSystem`NestedGrid`PackagePrivate`$state$$], TypeSystem`NestedGrid`PackagePrivate`anyHidden$ = TypeSystem`NestedGrid`PackagePrivate`anyHiddenQ[
                    TypeSystem`NestedGrid`PackagePrivate`$lastPath, TypeSystem`NestedGrid`PackagePrivate`$state$$], TypeSystem`NestedGrid`PackagePrivate`sortDirection$ = TypeSystem`NestedGrid`PackagePrivate`columnSortDirection[TypeSystem`NestedGrid`PackagePrivate`$lastPath, 
TypeSystem`NestedGrid`PackagePrivate`$state$$["SortPaths"], 
TypeSystem`NestedGrid`PackagePrivate`$state$$["SortDirections"]], TypeSystem`NestedGrid`PackagePrivate`haveData$ = Not[
FailureQ[
TypeSystem`NestedGrid`PackagePrivate`datasetInitialData[
                    TypeSystem`NestedGrid`PackagePrivate`$state$$]]], TypeSystem`NestedGrid`PackagePrivate`isKeyDummy$ = Not[
FreeQ[TypeSystem`NestedGrid`PackagePrivate`$lastPath, Keys]]}, 
Join[{
If[
Or[
Not[TypeSystem`NestedGrid`PackagePrivate`haveData$], 
Not[TypeSystem`NestedGrid`PackagePrivate`anyHidden$], TypeSystem`NestedGrid`PackagePrivate`isKeyDummy$],
                     Nothing, 
MenuItem["Show " <> Which[
                    TypeSystem`NestedGrid`PackagePrivate`lastPathType$ == "Item", "", TypeSystem`NestedGrid`PackagePrivate`lastPathType$ == "RowHeader", "Row", TypeSystem`NestedGrid`PackagePrivate`lastPathType$ == "ColumnHeader", "Column", True, ""], 
KernelExecute[
TypeSystem`NestedGrid`PackagePrivate`updateHiddenItems[
                    TypeSystem`NestedGrid`PackagePrivate`$state$$, TypeSystem`NestedGrid`PackagePrivate`$path$$, TypeSystem`NestedGrid`PackagePrivate`$vPos$$, TypeSystem`NestedGrid`PackagePrivate`$hPos$$, TypeSystem`NestedGrid`PackagePrivate`$grid$$, 
TypeSystem`NestedGrid`PackagePrivate`localHold[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]]][TypeSystem`NestedGrid`PackagePrivate`lastPath$, "remove"]], MenuEvaluator -> Automatic]], 
If[
Or[
Not[TypeSystem`NestedGrid`PackagePrivate`haveData$], 
TypeSystem`NestedGrid`PackagePrivate`pathEmptyQ[
                    TypeSystem`NestedGrid`PackagePrivate`$lastPath, TypeSystem`NestedGrid`PackagePrivate`$state$$], TypeSystem`NestedGrid`PackagePrivate`isKeyDummy$, And[TypeSystem`NestedGrid`PackagePrivate`allHidden$, TypeSystem`NestedGrid`PackagePrivate`headerHidden$]], Nothing, 
MenuItem["Hide " <> Which[
                    TypeSystem`NestedGrid`PackagePrivate`lastPathType$ == "Item", "", TypeSystem`NestedGrid`PackagePrivate`lastPathType$ == "RowHeader", "Row", TypeSystem`NestedGrid`PackagePrivate`lastPathType$ == "ColumnHeader", "Column", True, ""], 
KernelExecute[
TypeSystem`NestedGrid`PackagePrivate`updateHiddenItems[
                    TypeSystem`NestedGrid`PackagePrivate`$state$$, TypeSystem`NestedGrid`PackagePrivate`$path$$, TypeSystem`NestedGrid`PackagePrivate`$vPos$$, TypeSystem`NestedGrid`PackagePrivate`$hPos$$, TypeSystem`NestedGrid`PackagePrivate`$grid$$, 
TypeSystem`NestedGrid`PackagePrivate`localHold[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]]][TypeSystem`NestedGrid`PackagePrivate`lastPath$, "add"]], MenuEvaluator -> Automatic]], Delimiter}, 
If[
And[TypeSystem`NestedGrid`PackagePrivate`haveData$, 
MatchQ[TypeSystem`NestedGrid`PackagePrivate`lastPathType$, 
Alternatives["ColumnHeader", "KeyDummy"]], TypeSystem`NestedGrid`PackagePrivate`isLeafHeader$, 
Not[TypeSystem`NestedGrid`PackagePrivate`allHidden$]], {
If[
                    TypeSystem`NestedGrid`PackagePrivate`sortDirection$ =!= "Ascending", 
MenuItem["Sort", 
KernelExecute[
TypeSystem`NestedGrid`PackagePrivate`updateSort[
                    TypeSystem`NestedGrid`PackagePrivate`$state$$, TypeSystem`NestedGrid`PackagePrivate`$path$$, TypeSystem`NestedGrid`PackagePrivate`$vPos$$, TypeSystem`NestedGrid`PackagePrivate`$hPos$$, TypeSystem`NestedGrid`PackagePrivate`$grid$$, 
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]][TypeSystem`NestedGrid`PackagePrivate`lastPath$, "Ascending"]], MenuEvaluator -> Automatic], Nothing], 
If[TypeSystem`NestedGrid`PackagePrivate`sortDirection$ =!= "Descending", 
MenuItem["Reverse Sort", 
KernelExecute[
TypeSystem`NestedGrid`PackagePrivate`updateSort[
                    TypeSystem`NestedGrid`PackagePrivate`$state$$, TypeSystem`NestedGrid`PackagePrivate`$path$$, TypeSystem`NestedGrid`PackagePrivate`$vPos$$, TypeSystem`NestedGrid`PackagePrivate`$hPos$$, TypeSystem`NestedGrid`PackagePrivate`$grid$$, 
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]][TypeSystem`NestedGrid`PackagePrivate`lastPath$, "Descending"]], MenuEvaluator -> Automatic], Nothing], 
If[TypeSystem`NestedGrid`PackagePrivate`sortDirection$ =!= None, 
MenuItem["Unsort", 
KernelExecute[
TypeSystem`NestedGrid`PackagePrivate`updateSort[
                    TypeSystem`NestedGrid`PackagePrivate`$state$$, TypeSystem`NestedGrid`PackagePrivate`$path$$, TypeSystem`NestedGrid`PackagePrivate`$vPos$$, TypeSystem`NestedGrid`PackagePrivate`$hPos$$, TypeSystem`NestedGrid`PackagePrivate`$grid$$, 
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]][TypeSystem`NestedGrid`PackagePrivate`lastPath$, None]], MenuEvaluator -> Automatic], Nothing], Delimiter}, {}], {
MenuItem[
                    "Copy Position to Clipboard", 
KernelExecute[
TypeSystem`NestedGrid`PackagePrivate`toCurrentPosition[
                    TypeSystem`NestedGrid`PackagePrivate`copyClip]], MenuEvaluator -> Automatic], 
If[TypeSystem`NestedGrid`PackagePrivate`haveData$, 
MenuItem["Copy Data to Clipboard", 
KernelExecute[
TypeSystem`NestedGrid`PackagePrivate`toCurrentData[
                    TypeSystem`NestedGrid`PackagePrivate`$state$$, TypeSystem`NestedGrid`PackagePrivate`copyClip]], MenuEvaluator -> Automatic], Nothing], Delimiter, MenuItem["Paste Position in New Cell", 
KernelExecute[
TypeSystem`NestedGrid`PackagePrivate`toCurrentPosition[
                    TypeSystem`NestedGrid`PackagePrivate`cellPaste]], MenuEvaluator -> Automatic], 
If[TypeSystem`NestedGrid`PackagePrivate`haveData$, 
MenuItem["Paste Data in New Cell", 
KernelExecute[
TypeSystem`NestedGrid`PackagePrivate`toCurrentData[
                    TypeSystem`NestedGrid`PackagePrivate`$state$$, TypeSystem`NestedGrid`PackagePrivate`cellPaste]], MenuEvaluator -> Automatic], Nothing]}]]]]], FontFamily -> "Source Sans Pro", FontSize -> 14, FontWeight -> Plain}, Dividers -> All, FrameStyle -> GrayLevel[0.7490196078431373], Spacings -> {0, 0}, Alignment -> Left, BaseStyle -> {FontFamily -> "Source Sans Pro", FontSize -> 14, FontWeight -> Plain}], LineBreakWithin -> False, ContextMenu -> {}, NumberMarks -> False, ShowAutoStyles -> False]], TypeSystem`NestedGrid`PackagePrivate`initialQ = True}, 
Dynamic[
TypeSystem`NestedGrid`PackagePrivate`setupViewPath[
        TypeSystem`NestedGrid`PackagePrivate`$path$$, If[
Not[TypeSystem`NestedGrid`PackagePrivate`initialQ], 
Module[{TypeSystem`NestedGrid`PackagePrivate`tmpGrid$ = $Failed, TypeSystem`NestedGrid`PackagePrivate`tmpData$ = TypeSystem`NestedGrid`PackagePrivate`datasetData[
              TypeSystem`NestedGrid`PackagePrivate`$state$$]}, TypeSystem`NestedGrid`PackagePrivate`tmpGrid$ = If[
FailureQ[TypeSystem`NestedGrid`PackagePrivate`tmpData$], TypeSystem`NestedGrid`PackagePrivate`renderedGrid, 
TypeSystem`NestedGrid`PackagePrivate`renderGrid[
               TypeSystem`NestedGrid`PackagePrivate`$state$$, TypeSystem`NestedGrid`PackagePrivate`$path$$, TypeSystem`NestedGrid`PackagePrivate`$vPos$$, TypeSystem`NestedGrid`PackagePrivate`$hPos$$, TypeSystem`NestedGrid`PackagePrivate`$grid$$, 
TypeSystem`NestedGrid`PackagePrivate`localHold[
                TypeSystem`NestedGrid`PackagePrivate`$outputID$$]][
               TypeSystem`NestedGrid`PackagePrivate`tmpData$]]; If[
Not[
FailureQ[TypeSystem`NestedGrid`PackagePrivate`tmpGrid$]], TypeSystem`NestedGrid`PackagePrivate`renderedGrid = TypeSystem`NestedGrid`PackagePrivate`tmpGrid$]; Null]]; TypeSystem`NestedGrid`PackagePrivate`initialQ = False; TypeSystem`NestedGrid`PackagePrivate`$vPos$$; TypeSystem`NestedGrid`PackagePrivate`$hPos$$; If[
FailureQ[TypeSystem`NestedGrid`PackagePrivate`renderedGrid], 
TypeSystem`SparseGrid[
TypeSystem`H["(data no longer present)"]], TypeSystem`NestedGrid`PackagePrivate`renderedGrid]], TrackedSymbols :> {TypeSystem`NestedGrid`PackagePrivate`$vPos$$, TypeSystem`NestedGrid`PackagePrivate`$hPos$$}], DynamicModuleValues :> {}], TypeSystem`NestedGrid`PackagePrivate`$topBar$$ = Dynamic[
TypeSystem`NestedGrid`PackagePrivate`makeFramedBar[
TypeSystem`PackageScope`SubViewPathbar[
        TypeSystem`NestedGrid`PackagePrivate`$path$$, 
TypeSystem`NestedGrid`PackagePrivate`updateState[
         TypeSystem`NestedGrid`PackagePrivate`$state$$, TypeSystem`NestedGrid`PackagePrivate`$path$$, TypeSystem`NestedGrid`PackagePrivate`$vPos$$, TypeSystem`NestedGrid`PackagePrivate`$hPos$$, TypeSystem`NestedGrid`PackagePrivate`$grid$$, 
TypeSystem`NestedGrid`PackagePrivate`localHold[
          TypeSystem`NestedGrid`PackagePrivate`$outputID$$]]]], TrackedSymbols :> {TypeSystem`NestedGrid`PackagePrivate`$path$$}], TypeSystem`NestedGrid`PackagePrivate`$bottomBar$$ = Style[
Framed[
Dynamic[
Replace[TypeSystem`NestedGrid`PackagePrivate`mouseAnnotation$$, {TypeSystem`NestedGrid`PackagePrivate`$SliceMarker[
TypeSystem`NestedGrid`PackagePrivate`localHold[
             TypeSystem`NestedGrid`PackagePrivate`$outputID$$]][
            Null, 
Blank[]] -> "", TypeSystem`NestedGrid`PackagePrivate`$SliceMarker[
TypeSystem`NestedGrid`PackagePrivate`localHold[
             TypeSystem`NestedGrid`PackagePrivate`$outputID$$]][
Pattern[TypeSystem`NestedGrid`PackagePrivate`path$, 
Blank[]], 
Pattern[TypeSystem`NestedGrid`PackagePrivate`pathType$, 
Blank[]], 
Pattern[TypeSystem`NestedGrid`PackagePrivate`isLeafHeader$, 
Blank[]]] :> (
            Increment[
             TypeSystem`NestedGrid`PackagePrivate`$contextMenuTrigger]; TypeSystem`NestedGrid`PackagePrivate`$lastPath = TypeSystem`NestedGrid`PackagePrivate`path$; TypeSystem`NestedGrid`PackagePrivate`$lastPathType = TypeSystem`NestedGrid`PackagePrivate`pathType$; TypeSystem`NestedGrid`PackagePrivate`$lastPathIsLeafHeader = TypeSystem`NestedGrid`PackagePrivate`isLeafHeader$; TypeSystem`NestedGrid`PackagePrivate`$lastOutputID = TypeSystem`NestedGrid`PackagePrivate`localHold[
              TypeSystem`NestedGrid`PackagePrivate`$outputID$$]; TypeSystem`NestedGrid`PackagePrivate`makePathTrail[
             TypeSystem`NestedGrid`PackagePrivate`path$, TypeSystem`NestedGrid`PackagePrivate`makePathElements]),
            Null :> Spacer[10], Blank[] :> Spacer[10]}], TrackedSymbols :> {TypeSystem`NestedGrid`PackagePrivate`mouseAnnotation$$}], FrameStyle -> None, ImageMargins -> 0, FrameMargins -> 0, Alignment -> Top, ImageSize -> {Automatic, 15}], FontSize -> 1], TypeSystem`NestedGrid`PackagePrivate`mouseAnnotation$$ = Null}, DynamicWrapperBox[
DynamicBox[ToBoxes[
Dataset`DatasetContent[
         2, "Path" -> Hold[
           TypeSystem`NestedGrid`PackagePrivate`$path$$], "Grid" -> Hold[
           TypeSystem`NestedGrid`PackagePrivate`$grid$$], "State" -> Hold[
           TypeSystem`NestedGrid`PackagePrivate`$state$$], "VPos" -> Hold[
           TypeSystem`NestedGrid`PackagePrivate`$vPos$$], "HPos" -> Hold[
           TypeSystem`NestedGrid`PackagePrivate`$hPos$$], "TopBar" -> Hold[
           TypeSystem`NestedGrid`PackagePrivate`$topBar$$], "BottomBar" -> Hold[
           TypeSystem`NestedGrid`PackagePrivate`$bottomBar$$], "OutputID" -> Hold[
TypeSystem`NestedGrid`PackagePrivate`localHold[
            TypeSystem`NestedGrid`PackagePrivate`$outputID$$]]], StandardForm],
ImageSizeCache->{85., {47.6425, 53.3575}},
TrackedSymbols:>{TypeSystem`NestedGrid`PackagePrivate`$state$$, TypeSystem`NestedGrid`PackagePrivate`$grid$$}], TypeSystem`NestedGrid`PackagePrivate`mouseAnnotation$$ = MouseAnnotation[],
ImageSizeCache->{85., {47.6425, 53.3575}}],
BaseStyle->{LineBreakWithin -> False},
DynamicModuleValues:>{},
Initialization:>(
       TypeSystem`NestedGrid`PackagePrivate`$outputID$$ = CreateUUID[]),
UnsavedVariables:>{TypeSystem`NestedGrid`PackagePrivate`$outputID$$}],
     
Deploy,
DefaultBaseStyle->"Deploy"],
Dataset`InterpretDataset[1],
Editable->False,
SelectWithContents->True,
Selectable->False]\)]
Out[1]=

Create a Dataset:

In[2]:=
data = Dataset[{
   <|"a" -> 1, "b" -> "x", "c" -> {1}|>,
   <|"a" -> 2, "b" -> "y", "c" -> {2, 3}|>,
   <|"a" -> 3, "b" -> "z", "c" -> {3}|>,
   <|"a" -> 4, "b" -> "x", "c" -> {4, 5}|>}]
Out[2]=

Reformat it so that only three rows show and the background is cyan:

In[3]:=
ResourceFunction["FormatDataset"][MaxItems -> 3, Background -> Cyan][data]
Out[3]=

Apply a Query to data and format the results using the "Web" theme:

In[4]:=
ResourceFunction["FormatDataset"][DatasetTheme -> "Web"][
 Query[All, KeyDrop["b"]][data]]
Out[4]=

Apply a Query and use a postfix form of the function with iconized arguments to format the results using multiple styling options:

In[5]:=
Query[GroupBy[#b &], Total, "a"][data] // ResourceFunction["FormatDataset"][
Sequence[ItemDisplayFunction -> (Style[#, Purple, FontSize -> 18]& ), HeaderStyle -> Bold, Background -> LightBlue]]
Out[5]=

Scope (1) 

If the data to which the function is applied is not a Dataset to begin with, the function will convert it into a formatted Dataset:

In[6]:=
ResourceFunction["FormatDataset"][DatasetTheme -> "Scientific"][
 Range[10]]
Out[6]=

Applications (3) 

Take data on executions in the United States:

In[7]:=
executions = ResourceData["Executions in the United States"]
Out[7]=

Group the data by state, find the distribution of executed persons by race, reverse sort the states by total number of executions:

In[8]:=
bystate = ((GroupBy[#State &]/*ResourceFunction[
ResourceObject[<|"Name" -> "MapLevel", "ShortName" -> "MapLevel", "UUID" -> "643eb83e-c32c-41a8-830c-78e9282acb6c", "ResourceType" -> "Function", "Version" -> "1.0.0", "Description" -> "Create an operator that maps a function over data at a specified level", "RepositoryLocation" -> URL[
           "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"],
           "SymbolName" -> "FunctionRepository`$5c8c3349f3044fe1a584634b09381ccc`MapLevel", "FunctionLocation" -> CloudObject[
           "https://www.wolframcloud.com/obj/835b686f-f639-48e9-8faa-fe7a755e6bb7"]|>, {ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"}]][#Race &, {2}]/*Map[ResourceFunction[
ResourceObject[<|"Name" -> "ItemCounts", "ShortName" -> "ItemCounts", "UUID" -> "6f0e7df7-5f7c-4aa6-82f9-5ef19898e7c0", "ResourceType" -> "Function", "Version" -> "1.0.0", "Description" -> "A two-argument form of Counts that gives an association between a set of provided keys and the number of times those keys appear in a list", "RepositoryLocation" -> URL[
            "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"], "SymbolName" -> "FunctionRepository`$7a3a61c711cf4c5e90b66949a03cb158`ItemCounts", "FunctionLocation" -> CloudObject[
            "https://www.wolframcloud.com/obj/2b78e33b-78bd-4d4e-a640-a836b8c05b2f"]|>, ResourceSystemBase -> Automatic]][{"Asian", "Black",
          "Latino", "Native American", "Other", "White"}]]/*
      ReverseSortBy[Total])[executions]);

Display the results of the query by showing just the 5 states with the highest number of executions, while using a "Monochrome" theme:

In[9]:=
bystate // ResourceFunction["FormatDataset"][DatasetTheme -> "Monochrome", MaxItems -> 5]
Out[9]=

Highlight in lighter purple the number of Black persons executed:

In[10]:=
bystate // ResourceFunction["FormatDataset"][
  Background -> {None, {None, Lighter@Purple, {None}}}, MaxItems -> 5]
Out[10]=

One can store a format as a named variable and then deploy it on different datasets:

In[11]:=
bigPrint = ResourceFunction["FormatDataset"][ItemStyle -> 24, HeaderStyle -> 36];
In[12]:=
ResourceFunction[
ResourceObject[<|"Name" -> "MapReduceOperator", "ShortName" -> "MapReduceOperator", "UUID" -> "856f4937-9a4c-44a9-88ae-cfc2efd4698f", "ResourceType" -> "Function", "Version" -> "1.0.0", "Description" -> "Like an operator form of GroupBy, but where one also specifies a reducer function to be applied", "RepositoryLocation" -> URL[
       "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"], "SymbolName" -> "FunctionRepository`$ad7fe533436b4f8294edfa758a34ac26`MapReduceOperator", "FunctionLocation" -> CloudObject[
       "https://www.wolframcloud.com/obj/6d981522-1eb3-4b54-84f6-55667fb2e236"]|>, {ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"}]][First -> Last, Total][
  RandomInteger[{1, 4}, {100, 2}]] // bigPrint
Out[12]=
In[13]:=
Dataset[{
   <|"a" -> 1, "b" -> "x", "c" -> {1}|>,
   <|"a" -> 2, "b" -> "y", "c" -> {2, 3}|>,
   <|"a" -> 3, "b" -> "z", "c" -> {3}|>,
   <|"a" -> 4, "b" -> "x", "c" -> {4, 5}|>}] // bigPrint
Out[13]=

One can create a function using FormatDataset that permits customization and experimentation with formats:

In[14]:=
variableColorBigPrint[color_] := ResourceFunction["FormatDataset"][
  ItemStyle -> Directive[{24, color}], HeaderStyle -> Directive[{36, color}]]
In[15]:=
Dataset[{
   <|"a" -> 1, "b" -> "x", "c" -> {1}|>,
   <|"a" -> 2, "b" -> "y", "c" -> {2, 3}|>,
   <|"a" -> 3, "b" -> "z", "c" -> {3}|>,
   <|"a" -> 4, "b" -> "x", "c" -> {4, 5}|>}] // Through[{variableColorBigPrint[Purple], variableColorBigPrint[Green]}[#]] &
Out[15]=

Properties and Relations (1) 

The function compliments the resource function DatasetWithHeaders by permitting the results to be formatted:

In[16]:=
data = {{"a", "b", "c"}, {1, 2, 3}, {2, 4, -8}};
ResourceFunction[
ResourceObject[<|"Name" -> "DatasetWithHeaders", "ShortName" -> "DatasetWithHeaders", "UUID" -> "49505a7e-f65d-423b-a1b2-53e92ab9a80b", "ResourceType" -> "Function", "Version" -> "1.0.0", "Description" -> "One-step creation of a Dataset with named columns", "RepositoryLocation" -> URL[
      "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"], "SymbolName" -> "FunctionRepository`$3f4263244cee446ab527b0ae1f518123`DatasetWithHeaders", "FunctionLocation" -> CloudObject[
      "https://www.wolframcloud.com/obj/50144fee-8616-4ae7-be92-e840f03c1dc5"]|>, ResourceSystemBase -> Automatic]][data] // ResourceFunction["FormatDataset"][HeaderSize -> 4, HeaderBackground -> Orange, Background -> Black, ItemStyle -> White]
Out[16]=

Publisher

Seth J. Chandler

Version History

  • 1.0.0 – 29 June 2021

Related Resources

License Information