Show vertical line on hover in R Shiny dashboard - r

I would like to make a Shiny dashboard with e.g. a simple line chart like the one in the top left panel on this website:
https://inflation.ihs.ac.at
I know how to make the plot with ggplot2 and how to make a Shiny dashboard to display the graph (and different versions of it when inputs in the ui are changed).
However, I do not know how to include the vertical line that follows your cursor and how to display labels and values when you hover over certain values.
My question: Is it possible to make a dashboard like this without having knowledge of CSS/Java/some other programming language than R? I looked at the dygraph package which helped me program something similar to the dashboard on the website above but I am not sure if it includes the possibility to make specific adjustments to the hover options provided.
Ideally I would like to be able to specify the detailed hover options (length, width and color of the line and the labels/values, etc.) and still be able to make the original plot with ggplot2 which is obviously not the case if I plot my data using the dygraph package. Is that an option?

Not exactly what you want but close, with rAmCharts4:
library(rAmCharts4)
dat <- data.frame(
x = 1:10,
y = rnorm(10)
)
amLineChart(
data = dat,
xValue = "x",
yValues = "y",
alwaysShowBullets = TRUE,
cursor = list(axes = "x")
)

Related

rpivottable: How to Statically Show Values on rpivottable Where renderName is a Chart

Using rpivottable function in my code. rpivottable provides us readymade graph options which we can choose. eg 1. Heat map 2. Bar chart 3. Tree map 4. Horizontal stacked bar chart etc.
For example, when "Horizontal Bar Chart" is selected, whenever I hover over each bar it is showing appropriate value.
However, I want the value displayed on hover to be statically shown on the chart. So without hovering over, the viewer can see the value for each bar.
Is this possible?
(NOTE: This post has been edited so that the request is more clear)
You asked this a long time ago, but I've just now come across your question. I can help with this! Other than the treemap, all of the other charts are C3 charts.
In this example, I used the data mtcars. I've included more than the static labels here; you may find use for some of these other methods to customize your table.
rp <- rpivotTable(mtcars, rows = "mpg", cols=c("cyl"), width = "80%", height = "40%",
rendererOptions = list(
c3 = list(legend = list(show = FALSE), # hide legend
data = list(labels = TRUE), # label the data
size = list(width = "600", # control the size
height = "500"))))
If you are using the cran package, you'll have to run this line of code, as well.
rp$x$params$rendererOptions <- rp$x$params$rendererOptions[[0]]
I've forked their repo; it doesn't look like they are going to be updating that package anymore. I've fixed this problem in my fork. If you wanted to you could always install my repo instead: devtools::install_github("fraupflaume/rpivotTable")

Change information on hover of Plotly point

I'm using Plotly in R to make a scatter plot but currently when I hover over the point in my shiny app, the values corresponding to the x,y values appear. ex (19, 27.73k). However, I would like to change it to display a column corresponding to that data as well. ex (USA, 19, 27.73k) Would this be possible? IDK if relevant but current marker code
mode="markers",
marker = list(
opacity = 0.5,
size = 5
)) %>%
What you're looking for is hovertemplate, possibly in tandem with text. Without data it's hard to generate exactly what you need, but you should be able to figure it out at https://plotly.com/r/hover-text-and-formatting/

gvisBubbleChart with categories for shiny app

I'm looking for a versatile bubble chart.
In my shiny app it has to be able to adjust to two things:
It must be clickable. I need to read the selected bubble from the chart and use the selected input for other visualisations inside the app.
I have a categorial x-axis.
I was looking into gvisBubbleChart which seemed to fit very well, but it only responds to a numerical x-axis.
For example:
data <- data.frame(id = c(1,2,3,4,5),xvar = c("a","b","c","d","e"),yvar = c(7,2,5,8,1),sizevar = c(3,66,7,8,5),colorvar = rep(0,5))
plot(gvisBubbleChart(data,idvar = "id", xvar = "xvar", yvar = "yvar", sizevar = "sizevar",colorvar="colorvar"))
Changes the xaxis to 1.5:6.0 instead of the string.
Is there a way to work around this? It seems that the input has to be numerical, I could not find a native option to turn this off.
I'm also very open to any other suggested packages which serve my needs, for ggplot I'm not sure if I can make the clickable part work?
So I checked various sources, editing the googlevisBubble chart is possible with a lot of effort, too much for my case as this would be a very hard workaround.
Google Charts Bubble Charts categorical x and y axes instead of numeric
What I'm going to do is use plotly with ggplot for the dynamic input in my shiny app, the hole package looks very promising.
https://plot.ly/r/shinyapp-plotly-events/

Making pie chart's contours smoother on Shiny

I am trying to have a nice looking plot for two (or possibly more) continuous values in the form of a pie chart using ggplot2.
The code is the following :
library("ggplot2")
library("ggthemes") ## for theme_economist
df <- data.frame(origin=c('with','without'),value=c(24536,50456))
pie <- ggplot(df, aes(x = "",y=value, fill = origin))+
geom_bar(width = 1,stat="identity")+
coord_polar(theta = "y",start=pi/3)+
theme_economist()
The pie is relatively fine except that the contours of the pie seems to be a bit irregularly drawn.Of course when you export it as a pdf it looks fine but displayed in RStudio or Shiny it doesn't look nice at all.
Is there a way to change the resolution of the ggplot object directly or to make renderplot() aware that we want to display the image at a high resolution ?
I tried modifying the res argument of the renderPlot() function but it distorts the image and do not get rid of the irregularity of the border.
How to make the contours of the pie smoother on Shiny or RStudio directly ? Thanks.
To improve the resolution of the plot on Shiny you have to set the res argument to its default value of 72. It does not make a lot of sense to me but it worked just fine the resolution went from really bad to really nice !
However increasing its value further can lead to distortion of the image.
It seems that for now you cannot change the resolution of the plotting object itself before exporting it or rendering it into Shiny.

rCharts dPlot - How I increase area of the chart to 900 width/ 800 height and how to add Chart Title?

dPlots are wonderful and I am able to show huge amount of data very intuitively in seconds. I like it. Now I want to display that chart in bigger iframe. I tried to change height/width of dPlot no luck. I also like to add Title to chart. Please help.
I am using below sample code (the code provided by timelyportfolio (via github)
Title: Build the Chart and Test iframe
weblink: https://github.com/ramnathv/rCharts/issues/230
Here is some code to show how to modify width of the chart.
library(rCharts)
titanic <- as.data.frame(Titanic)
d1 <- dPlot(
Freq ~ Sex,
groups = "Survived",
data = titanic,
type = "bar"
)
d1$set(width = 1200)
I tested it on my laptop and it works. You need the dev branch of rCharts to run this.

Resources