From bdcb811e13bdf045b159a7ea88223f8a47593df4 Mon Sep 17 00:00:00 2001 From: Travis Gerke Date: Tue, 26 Mar 2024 20:34:22 -0700 Subject: [PATCH 1/2] template --- content/blog/2024-03-27-python-setup.Rmd | 37 ++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 content/blog/2024-03-27-python-setup.Rmd diff --git a/content/blog/2024-03-27-python-setup.Rmd b/content/blog/2024-03-27-python-setup.Rmd new file mode 100644 index 0000000..f06b7e8 --- /dev/null +++ b/content/blog/2024-03-27-python-setup.Rmd @@ -0,0 +1,37 @@ + + +--- +title: Set up python projects like R projects +description: How to mirror the rig, renv, and rproj frameworks in python +author: + - "Travis Gerke" +date: '2024-03-27' +slug: python-setup +categories: + - python +tags: + - tips +--- + +[crosstalk]: https://rstudio.github.io/crosstalk/ +[DT]: https://rstudio.github.io/DT/ +[rmdformats]: https://github.com/juba/rmdformats + +This post demonstrates use of the [[crosstalk]]{.pkg} extension to coordinate filtering across multiple [[DT]]{.pkg} `datatable` widgets. The process is embedded in a standard R Markdown document, and is an example of [server(Shiny)-less](https://www.brodrigues.co/blog/2021-03-02-no_shiny_dashboard/) dashboarding/reporting. + +## Objective + +I often need to create reports or dashboards that present information across multiple tables from a database. Frequently, this deliverable is best displayed as a filterable view of the tables themselves in a web browser. This can happen when a primary key in one table (e.g. subject ID) appears in multiple rows of another table (e.g. event based lines of therapy), and I don't want to rectangle the data into a single flat file because it would complicate or mask necessary information. + +A seemingly obvious solution here is Shiny, and that's certainly true when you have large data / are querying in real time against a database. However, if your data are small to mid-sized (MB, not GB), you can achieve the above goal in a single html page from R Markdown, without any Shiny server overhead. The following outlines a workflow I've been using to make this possible; something I wanted to document is how to use [[crosstalk]]{.pkg} when you're calling multiple [[DT]]{.pkg} `datatable` widgets in the same `filter_select()` call. + +### Simulate data + +Let's start by simulating some data that looks similar to what we would get from a clinical trial or other healthcare-related database. There will be three tables: demographics, treatments, and follow-up. The code to do this is a bit long, and ancillary to the main message of this post, so it's hidden below (but feel free to toggle and browse it if you wish!). + + +## Summary + +Note that this approach can work particularly well with [[rmdformats]]{.pkg} or other R Markdown theming. For example, here is the above workflow embedded in `rmdformats::robobook` which can be found in [this repo](https://github.com/tgerke/crosstalk-with-dt) with [corresponding interactive webpage](https://tgerke.github.io/crosstalk-with-dt/). Enjoy! From 56aa87fd55af214d563d88df5bdc48c91de7bd03 Mon Sep 17 00:00:00 2001 From: Travis Gerke Date: Tue, 26 Mar 2024 20:41:19 -0700 Subject: [PATCH 2/2] intro --- content/blog/2024-03-27-python-setup.Rmd | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/content/blog/2024-03-27-python-setup.Rmd b/content/blog/2024-03-27-python-setup.Rmd index f06b7e8..4a06b63 100644 --- a/content/blog/2024-03-27-python-setup.Rmd +++ b/content/blog/2024-03-27-python-setup.Rmd @@ -19,6 +19,11 @@ tags: [DT]: https://rstudio.github.io/DT/ [rmdformats]: https://github.com/juba/rmdformats +I just want my python projects to work like R projects always have. +I have a long-running joke about taking a python course where the instructor had to cancel a session because a python installation borked his machine (was this the lesson!?). +Why is setting up a python environment so hard? +And, with all due respect, Jupyter notebooks are not the future; I just want a line-by-line REPL. + This post demonstrates use of the [[crosstalk]]{.pkg} extension to coordinate filtering across multiple [[DT]]{.pkg} `datatable` widgets. The process is embedded in a standard R Markdown document, and is an example of [server(Shiny)-less](https://www.brodrigues.co/blog/2021-03-02-no_shiny_dashboard/) dashboarding/reporting. ## Objective