Displaying parameter values in report html
Hi,
Is there any way to include or access the report parameters in the report's html? This would really in giving viewers of a report more clarity on what parameters it was run with.
For example it's currently possible to bind the Report's title in the html content using :
<h1>{{ title }}</h1>
However the following does not work for parameters:
<p>{{ param_name }}</p>
Furthermore this would be extremely useful for cross-linking or drilling down into other reports using the same parameters.
Thanks!
-
Hi Sebastien!
You can do this with a bit of custom HTML and making sure you add your parameter as a column in your query. Here's an example report that does this:
https://modeanalytics.com/modeanalytics/reports/e968e09c5064
You will notice that the search parameter has been added as a column:
SELECT opponent, COUNT(touchdown_id) AS total_touchdowns, SUM(yards) AS yards, '{{search}}' AS search FROM benn.nfl_touchdowns WHERE team = '{{search}}' AND season = {{season}} GROUP BY 1
I then pull the parameter value using this and a bit more Javascript:
<script> var param = dataset.content[0].search; //Find "param" and "last" elements in page and set the contents of those elements (<span>'s in the title above) to the param and last variable values $("#param").text(param) //Use chart title "Chart Title" to replace with Tototal Touchdowns by {{search parameter}} var titles = { "Chart Title" : "Total Touchdowns by " + param, //Needs to be the query name + Results "Query 1 Results" : "Results for " + param }; //Need this timeout for things to render correctly setTimeout(function(){ //Set chart title to the new "Total Touchdowns by {{search parameter}} $(".chart-header").each(function() { var title = $.trim($(this).text()), trimmed = $.trim(title.slice(0,title.length - 28)); //console.log(title) if (trimmed in titles) { $(this).text(titles[trimmed]) } }) }, 1000);</script>
which sets the span for the report title (param)
<div class="mode-header embed-hidden"> <h1>{{ title }} <span id="param"></span>... </h1> ... </div>
Let me know how this works for you!
Reply -
Donna McGahan I would also *love* to have this feature. It would be an amazing addition to Reporting.
Another thing --- following the example, how would you add "Season" to the script? Currently, the script returns: "SUPPORT DEMO - Touchdowns by MIA Last Opponent: BUF" ... how do you get "SUPPORT DEMO - Touchdowns by MIA Last Opponent: BUF - 2014 Season" (or similar)?
Reply -
Chris Short If you add season as a column in your SQL, you can then add it as another parameter for use in the HTML. I've updated my example report to include season for report and chart title:
https://modeanalytics.com/modeanalytics/reports/e968e09c5064
Let me know if that makes sense. Thanks!
Reply -
+1 on this feature as well. It would be really nice to have the start date and end date parameters render on the report itself. Especially once it is saved via pdf so users can see the start date and end date ran on the report. For example, Report Start Date: "12/1/2016 " Report End Date: "1/1/2017"
Reply -
+1 for part of the original request as well, specifically the part about exposing parameters to be used in links to other reports.
I know it's possible to pass params to other pages by embedding links in the data tables (which is a huge help by the way), but it'd be great to be able to include params in something like the text editor where links can be added.
A use case would be when analyzing a user account where they are both a buyer and a seller on an ecommerce platform. Instead of including an analysis of both profiles, if the we were able to add free text saying "Evaluate Seller Metrics" on the Buyer page that appends the proper param to a report link (and vice versa on the other page), then that would help declutter report pages while showing proper linkage and navigability.
Reply -
+1 for this feature request.
My use case is around building links to other applications. So if I have set a parameter for {{ user_id }} = "bob@bobber.com", I will run a bunch of queries using that parameter in Mode, but I also need to construct links to other stuff. For example, <a href="https://some.other.app/?user_id= {{ user_id }}">Click here to view view this user in the directory</a>
Reply -
John Stetic Hey John! Sorry about it. Here's the example: https://modeanalytics.com/modeanalytics/reports/e968e09c5064
Reply -
My work around is pretty simple:
1) Create a second query with something like select '{{ user_id }}' as user.
2) Add this to your HTML:
<script>
var results = datasets.filter(function(d) {
return d.queryName == "YOUR QUERY NAME HERE";
})[0].content;var user = results[0].user;
</script>
3) Then you can use at at you please. In the initial example, you could just create the <p> tag with an id as such; <p id="userElement"></p>.
4) Then just add this below your javascript you already have document.getElementById("userElement").innerHTML = user;
I think this is a pretty simple work around here!
Hope this helps!
Reply