小编Abh*_*bhi的帖子

如何在 Shiny 上通过 downloadHandler 下载工作簿?

我们如何将工作簿保存在某个文件夹中并使其可供用户下载?

ref: Shiny + downloadHandler + Openxlsx 不生成 xlsx 文件

程序:

  • 创建数据
  • 另存为工作簿
  • 通过将其作为 xlsx 文件阅读,使其可供下载

即使工作簿已写入文件夹,下载该工作簿也会出错。

library(shiny)
library(openxlsx)
library(writexl)
library(tidyverse)
ui <- fluidPage(
  downloadButton("dl", "Download")
)

server <- function(input, output) {
  data1 = mtcars[,c(1,2)] %>% head() # data for Col 1 ,until Row 6
  data2 = gapminder::gapminder[,c(1,4)] %>% head() # data for Col 1 , Row from 8 until Row 13
  data3 = mtcars[,c(1,2)] %>% tail() # data for Col 1 , Row from 15 until Row 20

  # …
Run Code Online (Sandbox Code Playgroud)

r downloadfile shiny openxlsx

5
推荐指数
1
解决办法
884
查看次数

如何从闪亮的数据下载到多张纸上?

我们如何将数据从 Shiny 下载到命名每个工作表的多个工作表上?

比如下面ginberg把mtcars数据保存在sheet1中,我们可以把head(mtcars)保存在sheet2中吗?此外,我们可以不同地命名这些工作表,例如 sheet_data、sheet_head

参考:https : //community.rstudio.com/t/r-shiny-to-download-xlsx-file/18441/3 代码来自https://community.rstudio.com/u/ginberg

library(writexl)
ui <- fluidPage(
  downloadButton("dl", "Download")
)
server <- function(input, output) {
  data <- mtcars

  output$dl <- downloadHandler(
    filename = function() { "ae.xlsx"},
    content = function(file) {write_xlsx(data, path = file)}
  )

      ### Trial 1
      # output$dl <- downloadHandler(
      #   filename = function() { "ae.xlsx"},
      #   content = function(file) {        
      #     fname <- paste(file,"xlsx",sep=".")
      #     wb <- loadWorkbook(fname, create = T)#createWorkbook()
      #     createSheet(wb, name = "data")
      #     writeWorksheet(wb, head(mtcars), sheet …
Run Code Online (Sandbox Code Playgroud)

excel r shiny

3
推荐指数
1
解决办法
936
查看次数

如何在闪亮的浏览器模式下调试ggplot?

我们曾经使用浏览器检查反应值,但是当 ggplot 未呈现预期图形时,我们如何在反应模式下调试它?

library(shiny)

ui <- basicPage(
  plotOutput("plot1", click = "plot_click"),
  verbatimTextOutput("info")
)

server <- function(input, output) {
  output$plot1 <- renderPlot({
    browser() # Here, the browser stops but when run the below line, cannot see the plot in plots tab
    plot(mtcars$wt, mtcars$mpg) # or ggplot ...both not rendering plot in browser mode
  })

  output$info <- renderText({
    paste0("x=", input$plot_click$x, "\ny=", input$plot_click$y)
  })
}

shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)

debugging plot ggplot2 shiny

2
推荐指数
1
解决办法
336
查看次数

标签 统计

shiny ×3

r ×2

debugging ×1

downloadfile ×1

excel ×1

ggplot2 ×1

openxlsx ×1

plot ×1