I have started a new create-react-app that uses bokeh to render some plots. Since i have complex plots i need to be able to import/include a custom library that pull some modules from bokehjs.
How I do it: in my index.js file i include the lib like this
require('./_beadselection.ts')
my beadselection.ts file looks like this:
import {Span, SpanView} from "#bokeh/bokehjs"
import {Plot} from "#bokeh/bokehjs"
import {FactorRange} from "#bokeh/bokehjs"
import {Mapping} from "#bokeh/bokehjs"
import {BoxedFactor} from "#bokeh/bokehjs"
import * as p from "core/properties"
export class CpxSpanView extends SpanView {
model: CpxSpan
connect_signals(): void {
super.connect_signals()
this.connect(this.model.properties.selected.change, () => { this.on_selected() })
}
on_selected(): void {
let val = NaN
const rng = this.model.range.factors
const width = Math.round(Math.max(
3, this.model.plot.inner_width / (.5+this.model.range.synthetic(rng[rng.length-1])) * .5
))
if(this.model.selected >= 0 && this.model.selected < rng.length)
val = this.model.range.synthetic(rng[this.model.selected])
this.model.setv({line_width: width, location: isNaN(val) ? -1. : val});
}
}
export namespace CpxSpan {
export type Attrs = p.AttrsOf<Props>
export type Props = Span.Props & {
plot: p.Property<Plot>
range: p.Property<FactorRange>
selected: p.Property<number>
}
}
The errors that come up are these:
Compiled with problems:
ERROR in ./src/_beadselection.ts 4:0-37
Module not found: Error: Can't resolve 'core/properties' in '/home/ubuntu/reactAPP/react-flask-app/src'
ERROR in ./src/_beadselection.ts 5:33-41
export 'SpanView' (imported as 'SpanView') was not found in '#bokeh/bokehjs' (possible exports: ActionTool, AdaptiveTicker, AjaxDataSource, AllLabels, Annotation, AnnularWedge, Annulus, Arc, Arrow, ArrowHead, Ascii, Axis, BBoxTileSource, Band, BasicTickFormatter, BasicTicker, Bezier, BinnedTicker, BooleanFilter, Box, BoxAnnotation, BoxEditTool, BoxSelectTool, BoxZoomTool, ButtonTool, CDSView, Canvas, CanvasTexture, CartesianFrame, CategoricalAxis, CategoricalColorMapper, CategoricalMarkerMapper, CategoricalPatternMapper, CategoricalScale, CategoricalTickFormatter, CategoricalTicker, Charts, Circle, ColorBar, ColorMapper, Column, ColumnDataSource, ColumnarDataSource, CompositeTicker, ContinuousAxis, ContinuousColorMapper, ContinuousScale, ContinuousTicker, CoordinateMapping, CrosshairTool, CumSum, CustomAction, CustomJS, CustomJSExpr, CustomJSFilter, CustomJSHover, CustomJSTransform, CustomLabelingPolicy, DataRange, DataRange1d, DataSource, DatetimeAxis, DatetimeTickFormatter, DatetimeTicker, DaysTicker, Document, Dodge, EdgeCoordinates, EdgesAndLinkedNodes, EdgesOnly, EditTool, Ellipse, EllipseOval, EqHistColorMapper, Expression, FactorRange, Filter, FixedTicker, FreehandDrawTool, FuncTickFormatter, GMapOptions, GMapPlot, GeoJSONDataSource, GestureTool, Glyph, GlyphRenderer, GraphCoordinates, GraphHitTestPolicy, GraphRenderer, Grid, GridBox, GroupFilter, GuideRenderer, HArea, HBar, HTMLBox, HelpTool, HexTile, HoverTool, Image, ImageRGBA, ImageURL, ImageURLTexture, IndexFilter, InspectTool, Interpolator, IntersectRenderers, Jitter, Label, LabelSet, LabelingPolicy, LassoSelectTool, LayoutDOM, LayoutProvider, Legend, LegendItem, LinAlg, Line, LineEditTool, LinearAxis, LinearColorMapper, LinearInterpolationScale, LinearInterpolator, LinearScale, LogAxis, LogColorMapper, LogScale, LogTickFormatter, LogTicker, MapOptions, MathML, MathText, Maximum, MercatorAxis, MercatorTickFormatter, MercatorTicker, MercatorTileSource, Minimum, Models, MonthsTicker, MultiLine, MultiPolygons, NoOverlap, NodeCoordinates, NodesAndLinkedEdges, NodesOnly, NormalHead, NumeralTickFormatter, OpenHead, OpenURL, Oval, Palettes, PanTool, Panel, Patch, Patches, PlainText, Plot, Plotting, PointDrawTool, PolarTransform, PolyAnnotation, PolyDrawTool, PolyEditTool, PolySelectTool, PolyTool, PrintfTickFormatter, ProxyToolbar, QUADKEYTileSource, Quad, Quadratic, Range, Range1d, RangeTool, Ray, Rect, RedoTool, Renderer, RendererGroup, ResetTool, Row, SaveTool, ScalarExpression, Scale, ScanningColorMapper, Scatter, Segment, SelectTool, Selection, SelectionPolicy, ServerSentDataSource, SingleIntervalTicker, Slope, Spacer, Span, Spline, Stack, StaticLayoutProvider, Step, StepInterpolator, TMSTileSource, Tables, Tabs, TapTool, TeX, TeeHead, Text, TextAnnotation, Texture, TickFormatter, Ticker, TileRenderer, TileSource, Title, Tool, ToolProxy, Toolbar, ToolbarBase, ToolbarBox, ToolbarPanel, Tooltip, Transform, UndoTool, UnionRenderers, VArea, VBar, VeeHead, WMTSTileSource, WebDataSource, Wedge, WheelPanTool, WheelZoomTool, Whisker, WidgetBox, Widgets, XComponent, YComponent, YearsTicker, ZoomInTool, ZoomOutTool, _testing, documents, embed, index, logger, protocol, safely, set_log_level, settings, sprintf, version)
I guess I am not connecting them properly, I even added the full path to the library file from where SpanView should be pulled and it still does not like it.
import {Span, SpanView} from "../node_modules/#bokeh/bokehjs/build/js/lib/models/annotations"
This question already has answers here:
elm generate random number
(2 answers)
Closed 7 years ago.
What's a simple way to do this?
The documentation for Random.initialSeed says:
"A good way to get an unexpected seed is to use the current time."
http://package.elm-lang.org/packages/elm-lang/core/2.1.0/Random#initialSeed
After a ton of reading, I can only find "solutions" that are well beyond my understanding of Elm and Functional Programming. They also don't seem to be solutions to this problem.
I'm currently hardcoding:
Random.initialSeed 314
If you use a library, please include the name used to get it from elm package. I've seen a solution that says use Native.now but I can't figure out how to get that one.
stackoverflow is suggesting this one but I can't understand how to apply it to my usecase Elm Current Date
You can try case nelson's answer from How do I get the current time in Elm?
From elm repl:
> import Now
> import Random
> Now.loadTime |> round -- get current time in Int
1455406828183 : Int
> Now.loadTime |> round |> Random.initialSeed -- get the Seed
Seed { state = State 1560073230 678, next = <function>, split = <function>, range = <function> }
: Random.Seed
I also have the code on my repo here.
Note: don't forget "native-modules": true in elm-package.json.
Edit:
to try the code,
git clone https://github.com/prt2121/elm-backup.git
cd elm-backup/now
elm make Now.elm
add "native-modules": true in elm-package.json
elm repl
The simplest way I can think of is to use the Elm Architecture and Effects.tick mechanism to initialise the seed with a time value.
Here is an example of how this works:
import Html exposing (..)
import Html.Events exposing (onClick)
import Random exposing (Seed, generate, int, initialSeed)
import Time exposing (Time)
import Effects exposing (Effects, Never)
import Task exposing (Task)
import StartApp
type alias Model = { seed : Seed, value : Int}
type Action = Init Time | Generate
init : (Model, Effects Action)
init = (Model (initialSeed 42) 0, Effects.tick Init)
modelFromSeed : Seed -> (Model, Effects Action)
modelFromSeed seed =
let
(value', seed') = generate (int 1 1000) seed
in
(Model seed' value', Effects.none)
update : Action -> Model -> (Model, Effects Action)
update action model =
case action of
Init time ->
modelFromSeed (initialSeed (round time))
Generate ->
modelFromSeed model.seed
view : Signal.Address Action -> Model -> Html
view address model =
div []
[ text ("Current value: " ++ (toString model.value))
, br [] []
, button [onClick address Generate] [text "New Value"]
]
app : StartApp.App Model
app = StartApp.start
{ init = init
, update = update
, view = view
, inputs = []
}
main : Signal Html
main = app.html
port tasks : Signal (Task Never ())
port tasks = app.tasks