2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

redashのWidgetでJavaScriptを有効にする(v2.0.1での例)

2
Last updated at Posted at 2017-11-02

Redashにちょっとだけ手を加えたくJavaScriptを埋め込もうと思ったものの、
v1.0以降ではすんなり動かないようなのでなんとかしてみました。
試した環境はv2.0.1をUbuntu16にローカルインストールしたものです。

TextWidgetでコードを許可するよう設定する

.envに記載するなど、環境に応じてスクリプトを許可します。
本来はこれだけで動いてくれるのが理想なんだけども…

export REDASH_ALLOW_SCRIPTS_IN_USER_INPUT="true"

コードを編集

markdownフィルタのせいで動かないのではずしたよという情報もあったのですが

I can't use javascript in Text Box - Support - Redash Discourse
https://discuss.redash.io/t/i-cant-use-javascript-in-text-box/637

v2.0.1でフィルタを外すとREDASH_ALLOW_SCRIPTS_IN_USER_INPUTの設定が処理されなくなってしまいました。
なので、フィルタそのものの動作を変更。当然ながら、Markdownは使用できなくなります。

・redash.2.0.1.b3080での編集例

/opt/redash/redash.2.0.1.b3080/client/app/filters/markdown.js

@@ -1,4 +1,4 @@
-import marked from 'marked';
+//import marked from 'marked';

 export default function (ngModule) {
   ngModule.filter('markdown', ($sce, clientConfig) =>
@@ -7,7 +7,8 @@
          return '';
        }

-       let html = marked(String(text));
+//       let html = marked(String(text));
+       let html = String(text);
        if (clientConfig.allowScriptsInUserInput) {
          html = $sce.trustAsHtml(html);
        }

リビルド

本来はnpmインストールしてこれだけでいいはずなんですが…

$ cd /opt/redash/redash.2.0.1.b3080/
$ npm install
$ npm run build

ここも投稿時点ではいろいろ問題があったので、対処方法を別の投稿に記載しています。

redashビルドとエラー対応(2017/11 時点)
https://qiita.com/tomokin/items/c5204e1d5f73249b72d3

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?