rshinydtshinyscreenshot

Is there a way to update the css selector within the shiny screenshotButton as there's choices selected in pickerInput?


I'm using shiny library(shinyscreenshot). I have a datatable within a tabBox and would like the user to be able to download a screenshot of the datatable with a specific div id that changes based on the pickerInput. I've noticed, after I select choices in the pickerInput, the new datatable rendered has a different div id. The different div's for the datatables are as follows: #DataTables_Table_0, #DataTables_Table_1, #DataTables_Table_2, #DataTables_Table_3, etc.

Is there a way I can still use "screenshotButton()" and be able to update the selector to be whatever selector matches the string?

I ran into this issue when I used the following code and nothing downloaded after the first download:

screenshotButton(filename = "TEST.png",label = "Download",download = TRUE, scale =3, selector = "#DataTables_Table_0")

I thought about using an attribute selector similar to:

 [attribute~="value"] 

where my code would look something like this to capture a specific string match within the selector but no luck.

screenshotButton(filename = "TEST.png",label = "Download",download = TRUE, scale =3, [id~="DataTables_Table_"])

Also, I used the id = "#table" which produces a valid download but I would like to stick with the #DataTables_Table id as this would allow for a png which shows the datatable in the most compact, cropped format without any extra filters or tabs showing within the screenshot.

Thank you in advance.


Solution

  • You were very close! you can use the *= operator to aim for attribute that begins with selector:

    selector = "[id*='DataTables_Table_']"