rCharts使用Shiny的框自动缩放宽度和高度

laximzn5  于 2023-04-27  发布在  其他
关注(0)|答案(1)|浏览(162)

有没有什么方法可以让rCharts包中的图表在Shiny应用程序窗口中缩小/增加?我的意思是它应该根据框的宽度和高度进行调整,而不是超出框的区域。
我的部分代码:

# ui.r
fixedRow(
        column(width = 4,box(title = "Total Cases by Country", status = "warning",solidHeader = TRUE,showOutput("Chart3", "nvd3"),htmlOutput("other"),width = 12)),
        column(width = 4,box(title = "Country-specific pandemic statistics", status = "warning",solidHeader = TRUE,showOutput("Chart4", "HighCharts"),width = 12))
    )
# server.r
output$Chart4 <- renderChart2({
      dat <- data.frame(key = colnames(countryData())[c(6,8,10)], value = c(countryData()$TotalDeaths,countryData()$TotalRecovered,countryData()$ActiveCases))
      h1 <- hPlot(x = "key", y = "value", data = dat, type = "pie", title = countryData()$Country.Region)
      h1$chart(
        width = 500
      )
      return(h1)
    })

我的UI是基于特定宽度的框的列。我尝试了很多方法来实现目标,最后我设置了h1$chart(width=500),这并不能解决不同显示器分辨率的问题。

ffscu2ro

ffscu2ro1#

我在一个类似的线程中找到了一个解决方案-在shiny中自动调整rChart大小。
根据窗口自动设置图表宽度的工作代码:

# ui.r
fixedRow(
        column(width = 4,box(title = "Total Cases by Country", status = "warning",solidHeader = TRUE,plotOutput("plot2", height = "1px"),showOutput("Chart3", "nvd3"),htmlOutput("other"),width = 12)),
        column(width = 4,box(title = "Country-specific pandemic statistics", status = "warning",solidHeader = TRUE,plotOutput("plot1", height = "1px"),showOutput("Chart4", "HighCharts"),width = 12))eader = TRUE,leafletOutput("map"),width = 12))
    )
# server.r
output$Chart4 <- renderChart2({
      dat <- data.frame(key = colnames(countryData())[c(6,8,10)], value = c(countryData()$TotalDeaths,countryData()$TotalRecovered,countryData()$ActiveCases))
      h1 <- hPlot(x = "key", y = "value", data = dat, type = "pie", title = countryData()$Country.Region)
      h1$set(width = session$clientData$output_plot1_width)
      return(h1)
    })
  • 必须将session参数添加到服务器。

相关问题