googleCharts resets in size in Shiny after second load - r

So I'm using the googleCharts package in my Shiny app and creating a line chart.
I have a function that creates a different kind of main panel with tabsetpanel depending on the options the user selects. The first load works fine, but when I switch options in my app and it loads the main panel page the second time, the chart shrinks in size unless I specify an exact height and width in options.
The interesting part is if I select the options so the main panel that's created doesn't have a chart, then select one that does, it resets and works fine again. So it's almost like some kind of reactive problem where its saving the wrong page size and not doing a full load.
Any ideas on what I could do? Is there a way for me to force a refresh/reload of the mainPanel?

I actually ended up solving this using invalidateLater, but I would appreciate it if there's a different solution too, since the user can see the chart being redrawn with this solution

Related

How to freeze a part of dashboard body in R Shiny?

I have an R Shiny dashboard.
In its body, I have some user inputs located in the top part of the body, e.g. sliders and text inputs.
Underneath user inputs, I have charts that are being rendered when a user changes inputs.
There are several charts located in several rows, therefore a user needs to scroll down to go through all of them.
I want to freeze the upper part of the dashboard body, so when a user scrolls down, all user inputs are still being visible. Something similar to Excel's "Freeze Rows" functionality.
How do I do that?
Please check the function absolutePanel() from the library markdown. It is exactly what you are looking for!
I'm attaching a hyperlink of the same below.
Absolutely Positioned Panels

How to extend time of active code highlight in a shiny app?

I am working on a Shiny project where the Shiny app contains large amount of code. I want to debug the app's code interactively using:
runApp("ShinyApp.R", launch.browser = TRUE, display.mode = "showcase")
The display.mode = "showcase" argument displays the active code next to the app in my browser and highlights the area where the user interacted with the app. Here is a good example of how this works: https://shiny.rstudio.com/articles/action-buttons.html
Another example of how it can be used is mentioned in this answer: How do I highlight active code in a shiny app?
What I found challenging is that because my app's script contains over 800 lines of code, I am not able to see the highlighting when it occurs (it disappears too fast). As mentioned here: https://shiny.rstudio.com/articles/display-modes.html, the highlighting disappears after a few moments.
My questions are:
Is it possible to increase the time until the highlighted area disappears?
Is there a way to force the side bar to scroll to the area where the highlighting occurs?
Thank you for any suggestions or answers!
Yes and yes, but you have to edit the source code and it's Javascript. The code in need of modification lives in inst/www/shared/shiny-showcase.js. I already made the code changes on my fork of Shiny if you want to start there.
For your first question about highlight duration, this is handled by the JQuery highlight effect on line 112:
// End any previous highlight before starting this one
jQuery(el)
.stop(true, true)
.effect("highlight", null, 5000);
The original is 1600, or 1.6 seconds, so I upped it here to 5 seconds. You can change it to whatever you think is best.
Your second question about scrolling to the active/highlighted code, isn't included in the original script but the ability to do is baked into web elements and called element.scrollIntoView(). I just inserted this bit of code immediately after the highlighting block:
// Scroll to highlighted element
el.scrollIntoView({behavior: 'smooth'});
el is variable name currently pointing to the active code region to highlight.
Here is hosted working demo of the tweaks in action.

R Leaflet does not show legend when embedded in Shiny Dashboard

The map above renders perfectly fine in the following scenarios:
List item
RStudio Viewer
Shiny app
Shiny app using a minimal Shiny dashboard sceleton
When including the map in an existing, pretty complex Shiny dashboard, the looks as follows:
Obviously, the legend is missing. On top of that, the "reset view" action button has no effect.
Without posting the complete code of the complex shiny dashbboard, I would like make the following comments:
I have disabled all custom JS code and CSS
I use a bare "renderLeaflet" function without additional arguments
I have also tried to display the leaflet in a bare dashboard box without any further arguments
Any obvious culprit anyone could think of causing this issue? Anyone observed similar issues?
I wonder if you solved the issue. I noticed the legend of a raster layer disappears when using the function d3heatmap, for instance d3heatmap(mtcars, scale="column", colors="Blues"). When the line with the heatmap is commented out the dashboard knites just fine -even when the library d3heatmap is loaded. I used the code from this example. Oh I just noticed this has been addressed and solved in other questions, for example here.

uiOutput not displaying with shiny server

I have a shiny app that is working fine locally, whether I open it in a window or the browser, but after putting it onto our shiny server I am getting some unexpected behavior.
I have two plots that get displayed using uiOutput. The first displays after loading a data file, and the second is just a zoomed plot which appears when the user selects a region from the first plot and double clicks. After putting this app on our server and using it in a browser, the first plot appears when the user uploads a file, but the second plot will not display (it is completely blank - no data points, axes or labels).
What is strange is that the data in this second plot can still be interacted with. I have included hover functionality so that when the user hovers over a point in the second plot, information gets displayed about the point in a small text window. Even though the second plot never appears, if I move the mouse over the region where the plot should be, this hover information gets displayed correctly. Depending on the size of the region selecting for zooming (i.e. if it is large), the zoomed image may not fit in the window making scrollbars necessary. If I select a large region for zooming, scrollbars appear as if the image is there, but the plot is as I said blank. I can render the zoomed plot as a pdf and that looks correct, but this isn't what I want.
As I said, everything works fine locally and this only happens after putting the app on our server. The same thing happens in Firefox, Safari and Chrome. This has to be something related to the shiny server but I have no idea what as both plots are being rendered in the same way.
I've managed to figure this out. In server.R when I generate the zoomed plot, I am doing two things. First, I am creating a pdf as follows:
pdf("z_plot.pdf")
plot()
...
dev.off()
The purpose of this is to have a plot that can be downloaded if required. After this, I am issuing the commands to render the plot in my shiny app. This is all being done in the same reactive expression, which for some reason works locally but when run on a shiny server only the pdf gets generated. I just had to separate the plotting commands into two reactive expressions and everything worked fine.

Altering The Sorting Arrows In an R Shiny tabPanel

I didn't see anything here or in http://shiny.rstudio.com/reference/shiny that seems to hit on this problem.
In an R Shiny tabPanel output, the sorting arrows align with the right side of the search fields at the bottom of the page.
Here's a pretty good example:
http://shiny.rstudio.com/gallery/datatables-options.html
Is there a way to make them align just to the right of the column name text up top?
Alternatively (or possibly both), is there a way to change the color of the arrows?
The default greyish doesn't really stand out. Bonus points to make the up and down arrows different colors.
Doing it directly in RShiny is best, but I could muddle my way through .js or .css if needed.
I'm trying to head off imminent support requests of "the column is sorting wrong" and "I can't see the arrows" before I push into production.
At the bottom of that shiny example you showed they show that you can pass in through the options parameter options to the rendering for the DataTable table, via the shiny::renderDataTable() function.
Hopefully the http://datatables.net/ site has documentation on what you want if it's indeed possible
If you look at Developer Tools on the http://shiny.rstudio.com/gallery/datatables-options.html page maybe you can see what element would need to be changed.

Resources