小编Car*_*lla的帖子

让 downloadButton 与 observeEvent 一起使用

我想添加功能,一旦用户downloadButton在我闪亮的应用程序中点击,就会给予用户反馈(例如,它会给用户一条警告消息或在点击后切换 ui 元素)。本质上,我希望能够downloadButton下载一些数据表现得像actionButton,以便它响应事件触发器。这可能吗?这是我设置代码的方式:

ui <- fluidPage(
  useShinyjs(),

  downloadButton("download", "Download some data")
)

server <- function(input, output, session) {

  observeEvent(input$download, {  # supposed to alert user when button is clicked
    shinyjs::alert("File downloaded!")  # this doesn't work
  })

  output$download <- downloadHandler(  # downloads data
    filename = function() {
      paste(input$dataset, ".csv", sep = "")
    },
    content = function(file) {
      write.csv(mtcars, file, row.names = FALSE)
    }
  )

}

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

这似乎只有在我更改downloadButton …

r shiny

7
推荐指数
1
解决办法
2719
查看次数

如何重命名 Shiny renderTable 中的列?

我在 Shiny 中使用 renderTable 来显示表格。我在重命名输出中的列名时遇到问题。

服务器.R:

reactive.tables <- reactiveValues()

output$lump.sum <- renderTable(
  if(input$my.password != am.password$password){
    data.frame(`There is no` = "report")
  } else {
    print(1)
    reactive.tables$occupancies %>%  # sum amounts by company
      group_by(company) %>%
      summarise(lump.sum.2 = sum(lump.sum.2), n = n()) %>%
      na.omit
  },
  colnames(output$lump.sum.2) = c("company", "lump sum", "occupancies")
)
Run Code Online (Sandbox Code Playgroud)

在响应式上下文之外重命名列似乎工作正常。但是,每次我在此反应式数据框中指定 colnames 参数时,都会收到以下错误:

ERROR: Error sourcing C:\Users\Carlos\AppData\Local\Temp\RtmpmmVUym\fileb803ae92d13
Run Code Online (Sandbox Code Playgroud)

任何建议将不胜感激。

formatting r shiny

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

标签 统计

r ×2

shiny ×2

formatting ×1