我面临着一个特定的挑战,并提出了一个解决方案.不过,我不确定这是不是一个优雅的解决方案.要求改进.
Challenge个
I am developing a shiny app using shinydashboard with a page with multiple boxes. Each box may contain a plolty plot or a DT table. I am providing an actionButton
in the footer of each box which allows a modalDialog
to be opened, displaying a larger version of the plot.
我发现了Joe cheng here的一个旧注释,它显示了一种将相同的renderPlot
调用链接到两个输出对象的方法.只要我在我的UI文件中调用一个对象,在modalDialog函数中调用另一个对象,它就可以工作.
然而,我想要控制绘图中的各种字体大小:在zoom 的绘图中,我希望使用比正常渲染的大字体更大的字体.我也不想冒险涉足Java脚本解决方案.
一个人可以通过复制renderPlotly
个不同字体大小的函数来强迫自己完成这一任务.但我想重用现有的renderPlotly
个函数;在我的例子中,该函数相当长.
Solution个
- 创建一个函数,我将其命名为
renderDynamic
,它以字体大小列表作为参数 - 该函数返回
renderPlotly
个对象
使用虹膜作为数据集:
renderDynamic <- function(pars = list(tick_font_size = 14, title_font_size = 18)) {
tick_font_size <- pars[[1]]
title_font_size <- pars[[2]]
return(
renderPlotly({
plot <- plot_ly(data = iris, x = ~Sepal.Length, y = ~Sepal.Width,
type = 'scatter', mode = 'markers',
color = ~Species,
marker = list(size = 10, opacity = 0.7))) %>%
layout(
xaxis = list(
tickfont = list(size = tick_font_size),
titlefont = list(size = title_font_size)),
yaxis = list(
tickfont = list(size = tick_font_size),
titlefont = list(size = title_font_size))
plot
})
)
})
output$plot_normal <- renderDynamic(pars = list(tick_font_size = 15, title_font_size = 18, slider_font_size = 15))
output$plot_zoom <- renderDynamic(pars = list(tick_font_size = 22, title_font_size = 22, slider_font_size = 18))
有什么 idea 吗?