Skip to content

Commit f656dcc

Browse files
authored
feat: preview r code in connect to read pin (#223)
1 parent d6c6778 commit f656dcc

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

pins/boards.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,12 @@ def prepare_pin_version(self, pin_dir_path, x, name: "str | None", *args, **kwar
11231123
# TODO(compat): set display none in index.html
11241124
context["data_preview"] = json.dumps({})
11251125

1126+
# do not show r code if not round-trip friendly
1127+
if meta.type in ["joblib"]:
1128+
context["show_r_style"] = "display:none"
1129+
else:
1130+
context["show_r_style"] = ""
1131+
11261132
# render html template ----
11271133

11281134
from jinja2 import Environment

pins/rsconnect/html/index.html

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<h3>{{pin_name}}</h3>
3434
{% if pin_metadata %}
3535
<p>
36-
{% if date %}<b>Last updated:</b> {{ date }} &bull;{% endif %}
36+
{% if date %}<b>Last updated from Python:</b> {{ date }} &bull;{% endif %}
3737
<b>Format:</b> {{ pin_metadata.type }} &bull;
3838
<b>API:</b> v{{ pin_metadata.api_version }}
3939
</p>
@@ -50,15 +50,27 @@ <h3>{{pin_name}}</h3>
5050
<h3>Python Code</h3>
5151

5252
<pre id="pin-python" class="pin-code"><code class="python">from pins import board_connect
53+
from dotenv import load_dotenv
54+
load_dotenv()
55+
5356
board = {{board_deparse}}
5457
board.pin_read("{{pin_name}}")</code></pre>
5558

5659
<script type="text/javascript">
5760
hljs.registerLanguage("python", highlight_python);
61+
hljs.registerLanguage("r", highlight_r);
5862
hljs.initHighlightingOnLoad();
5963
</script>
6064
</section>
6165

66+
<section style="{{ show_r_style }}">
67+
<h3>R Code</h3>
68+
<pre id="pin-r" class="pin-code"><code class="r">library(pins)
69+
70+
board <- board_connect(auth = "envvar")
71+
pin_read(board, "{{pin_name}}")</code></pre>
72+
</section>
73+
6274
<section style="{{ data_preview_style }}">
6375
<h3>Preview <small>(up to 100 rows)</small></h3>
6476
<div data-pagedtable style="height: 25em;">

pins/tests/_snapshots/test_board_pin_write_rsc_index_html/index.html

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<h3>derek/test_rsc_pin</h3>
3434

3535
<p>
36-
<b>Last updated:</b> 2020-01-13 23:58:59 &bull;
36+
<b>Last updated from Python:</b> 2020-01-13 23:58:59 &bull;
3737
<b>Format:</b> csv &bull;
3838
<b>API:</b> v1
3939
</p>
@@ -59,15 +59,27 @@ <h3>derek/test_rsc_pin</h3>
5959
<h3>Python Code</h3>
6060

6161
<pre id="pin-python" class="pin-code"><code class="python">from pins import board_connect
62+
from dotenv import load_dotenv
63+
load_dotenv()
64+
6265
board = board_connect(server_url='http://localhost:3939')
6366
board.pin_read("derek/test_rsc_pin")</code></pre>
6467

6568
<script type="text/javascript">
6669
hljs.registerLanguage("python", highlight_python);
70+
hljs.registerLanguage("r", highlight_r);
6771
hljs.initHighlightingOnLoad();
6872
</script>
6973
</section>
7074

75+
<section style="">
76+
<h3>R Code</h3>
77+
<pre id="pin-r" class="pin-code"><code class="r">library(pins)
78+
79+
board <- board_connect(auth = "envvar")
80+
pin_read(board, "derek/test_rsc_pin")</code></pre>
81+
</section>
82+
7183
<section style="">
7284
<h3>Preview <small>(up to 100 rows)</small></h3>
7385
<div data-pagedtable style="height: 25em;">

0 commit comments

Comments
 (0)