Thursday, October 29, 2020

VBA macro to split excel sheets into separate files

See https://trumpexcel.com/split-each-excel-sheet-into-separate-files/


'Code Created by Sumit Bansal from trumpexcel.com
Sub SplitEachWorksheet()
Dim FPath As String
FPath = Application.ActiveWorkbook.Path
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each ws In ThisWorkbook.Sheets
    ws.Copy
    Application.ActiveWorkbook.SaveAs Filename:=FPath & "\" & ws.Name & ".xlsx"
    Application.ActiveWorkbook.Close False
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True 

End Sub 

Saturday, May 2, 2020

plotly event_register

* The `event` argument of the `event_data()` function now supports the following events: `plotly_selecting`, `plotly_brushed`, `plotly_brushing`, `plotly_restyle`, `plotly_legendclick`, `plotly_legenddoubleclick`, `plotly_clickannotation`, `plotly_afterplot`, `plotly_doubleclick`, `plotly_deselect`, `plotly_unhover`. For examples, see `plotly_example("shiny", "event_data")`, `plotly_example("shiny", "event_data_legends")`, and `plotly_example("shiny", "event_data_annotation")`,

* New `event_register()` and `event_unregister()` functions for declaring which events to transmit over the wire (i.e., from the browser to the shiny server). Events that are likely to have large overhead are not registered by default, so you'll need to register these: `plotly_selecting`, `plotly_unhover`, `plotly_restyle`, `plotly_legendclick`, and `plotly_legenddoubleclick`.


Tuesday, April 28, 2020

Deploy Dash application on Apache

Following are example scripts to deploy Dash application in a sub-domain on an Apache web server installed with Flask and Dash modules. Hopefully this will be useful to someone who also experienced annoying issues of Dash stuck at a white window with “Loading…” or “dash error loading layout”.

Assume we will deploy the application in https://www.example.com/user1/myapp. First setup wsgi script, say "index.wsgi", in the application folder with the following content:

import sys
# add your app directory to the sys.path
project_home = u'/home/users/user1/www/myapp' #specify to the correct path
if project_home not in sys.path:
    sys.path = [project_home] + sys.path
# need to pass the flask app as "application" for WSGI to work
# for a dash app, that is at app.server
# see https://plot.ly/dash/deployment
from dashing_demo_app import app
application = app.server
app.config.update({
    # as the proxy server will remove the prefix
    #'routes_pathname_prefix': '',
    # the front-end will prefix this string to the requests
    # that are made to the proxy server
    'requests_pathname_prefix': '/user1/myapp/index.wsgi/'
})

Please note that you need to specify requests_pathname_prefix to your url path, as it is the key to resolve the above issues of loading Dash app.

An example app script "dashing_demo_app.py" can be found from the reference link at the end (also copied below)
import dash
import dash_core_components as dcc
import dash_html_components as html # for deployment, pass app.server (which is the actual flask app) to WSGI etc
app = dash.Dash() app.layout = html.Div(children=[
html.H1(children='Hello Dash'), html.Div(children='''
Dash: A web application framework for Python.
'''), dcc.Graph(
id='example-graph',
figure={
'data': [
{'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
{'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
],
'layout': {
'title': 'Dash Data Visualization'
}
}
)
])

The original wsgi script and demo script are from https://github.com/conradho/dashingdemo/

Sunday, April 19, 2020

Writing R in VS Code

Install the following software:

To enable radian console in VSCode:

  • Turn on r.bracketdPaste
  • Set r.rterm.windows to the path of radian
  • Clear setting of r.rterm.option


Reference
https://renkun.me/2019/12/11/writing-r-in-vscode-a-fresh-start/

Wednesday, February 5, 2020