Skip to content

Instantly share code, notes, and snippets.

@helgasoft
helgasoft / notes
Last active May 3, 2024 20:01
echarty announcements and temporary notes
#' This gist is for echarty announcements and notes
#' Comments are temporary, periodically deleted.
#' If you like echarty, please consider granting a Github star ⭐.
library(echarty)
data.frame(x = seq.int(1, 5, 1),
y = seq.int(1, 10, 2)) |>
ec.init(
series.param= list(
type='line', symbolSize= 10,
@helgasoft
helgasoft / app.R
Last active March 11, 2024 15:22
Demo Shiny: Leaflet JS plugin - layer control for grouping overlays
#' Demo - using Leaflet JS plugins in R and Shiny
#' directions from https://gist.github.com/jcheng5/c084a59717f18e947a17955007dc5f92
#' implementing groupings to overlay layers :
#' https://github.com/ismyrnow/leaflet-groupedlayercontrol
#' todo: would be nice to addMarkers to group layers from R, not only from JS
library(shiny)
library(leaflet)
library(htmlwidgets)
@helgasoft
helgasoft / app.R
Last active March 9, 2024 07:14
Echarty Translate Assistant - JavaScript data to R
library(shiny)
library(stringr)
library(echarty)
library(rclipboard) # for clipboard Copy button
library(formatR)
if (FALSE) { # notes
#' problem plot with Chinese chars:
#' text='<U+6F0F><U+6597><U+56FE>' > Sys.getlocale()
@helgasoft
helgasoft / app.R
Last active January 23, 2024 22:41
Coding Helper for echarty
#'----------- echarty coding helper ------------
#' Please report bugs and ask questions in https://github.com/helgasoft/echarty/issues
#' run in RStudio with command demo(coder), or demo(coder, package='echarty')
stopifnot('session non-interactive'= interactive())
library(shiny)
library(shinyjs)
library(shinybusy)
library(dplyr)
@helgasoft
helgasoft / dset.2.series.R
Created September 26, 2023 23:47
R | ECharts | dataset columns referenced in two series
set.seed(22)
data <- tibble(x = 2 * pi * (1:100)/100) |>
mutate(
y1_bar = 0.5 * (sin(x)) + 1,
y2_bar = 0.5 * (sin(x)) - 1,
deltaY1 = rnorm(100, sd = 0.1),
deltaY2 = rnorm(100, sd = 0.1),
y1 = y1_bar + deltaY1,
y2 = y2_bar + deltaY2,
sizeY1 = abs(deltaY1),
@helgasoft
helgasoft / shiny.resize.R
Created October 2, 2021 03:09
R | ECharts | dynamic resize with echarty
# https://echarts.apache.org/en/api.html#echartsInstance.resize
# https://echarts.apache.org/examples/en/editor.html?c=line-easing
library(shiny); library(dplyr); library(echarty)
ui <- fluidPage( titlePanel("Resize with echarty"),
fluidRow(ecs.output('chart')),
checkboxInput('toggle900','Toggle Size 900px'),
checkboxInput('toggle400','Toggle Size 400px')
)
@helgasoft
helgasoft / shiny.bind2
Last active May 19, 2023 14:19
Binding two ECharts without connect
library(shiny)
library(tidyverse)
library(echarty)
ui <- fluidPage(
HTML("Binding two charts on <b>inside zoom</b> only<br />
Tooltips could be bound too, by `axis`<br />
Alternative to ECharts <a href='https://echarts.apache.org/en/api.html#echarts.connect'>connect</a><br />
Solution adapted from <a href='https://github.com/apache/echarts/blob/12f6620c25eb96faa3e9f9fbc13a076c3c8bdbbc/test/connect-manually.html'>this code</a>"),
tags$head(tags$script(HTML("
@helgasoft
helgasoft / app.R
Last active April 18, 2023 18:25
Bathymetry demo with echarty
#' echarty demo for marmap
library(shiny)
library(shinydashboard)
library(shinybusy)
library(echarty)
library(marmap)
ui = dashboardPage(title='marmap', dashboardHeader(title='Bathymetry Demo'),
sidebar = dashboardSidebar(
fluidRow( column(12,
@helgasoft
helgasoft / svg.timeline.R
Last active January 22, 2023 14:22
R | ECharts | custom SVG map with timeline
library(echarty)
url <- 'https://test.softpower.tw/echartstw/example/svg/football.svg'
svg <- url |> readLines(encoding='UTF-8') |> paste0(collapse="")
p <- ec.init(preset=FALSE,
backgroundColor= '#228b22',
geo= list("map"="football"),
title= list(text ='2014 World Cup', textStyle=list( color='#FFFF00'),
subtext='original JS code', subtextStyle= list(color='#FFFF00'),
sublink='https://test.softpower.tw/echartstw/example/map19.html'
),
@helgasoft
helgasoft / rasta.leaf.R
Created December 22, 2022 02:00
Raster overlay on Leaflet map
# Expanding on the great code from Milos Popovic
# new display as layer on Leaflet map, instead of ggplot
# original: https://github.com/milos-agathon/mapping-raster-files-with-terra-in-r
################################################################################
# Mapping OSM and satelitte data with terra in R
# Milos Popovic
# 2022/09/22
################################################################################