DT和downloadButton应用

library(shiny)
library(DT)
ui <- shinyUI(
fluidPage(
titlePanel("DT test"),
downloadButton('downloadData', 'Download'), fluidRow(
DT::dataTableOutput("table")
)
)
)
server <- shinyServer(function(input, output) { output$table <- DT::renderDataTable(DT::datatable({
mtcars
}, rownames = FALSE)) output$downloadData <- downloadHandler(
filename = 'test.csv',
content = function(file) {
write.csv(mtcars, file)
}
)
}) shinyApp(ui,server)

downloadButton 中验证结果输出

一种情况是通过shinyjs,只有输入时,才显示下载按钮:

library(shiny)

ui <- fluidPage(
shinyjs::useShinyjs(),
textInput("text", "content", "", placeholder = "please insert something"),
shinyjs::hidden(downloadButton("download"))
) server <- function(input, output, session) {
output$download <- downloadHandler(
filename = "file.csv",
content = function(file) {
write.csv(data.frame(content = input$text), file)
}
) observeEvent(input$text, {
if (input$text == "")
shinyjs::hide("download")
else
shinyjs::show("download")
})
} shinyApp(ui, server)

另一种情况是downloadButton搭配uiOutput,即只有输出结果出现时,下载按钮才出现。

#ui端
uiOutput("download")
#server端
output$download <- renderUI({
if(!is.null(input$file1) & !is.null(input$file2)) {
downloadButton('OutputFile', 'Download Output File')
}
})

https://stackoverflow.com/questions/44179974/display-download-button-in-shiny-r-only-when-output-appears-in-main-panel

添加进度条

但不是真正的程序进度。

# Only run examples in interactive R sessions
if (interactive()) {
options(device.ask.default = FALSE) ui <- fluidPage(
plotOutput("plot")
) server <- function(input, output) {
output$plot <- renderPlot({
withProgress(message = 'Calculation in progress',
detail = 'This may take a while...', value = 0, {
for (i in 1:15) {
incProgress(1/15)
Sys.sleep(0.25)
}
})
plot(cars)
})
} shinyApp(ui, server)
}

https://shiny.rstudio.com/articles/progress.html

如何确保仅在使用Shiny按下操作按钮时才触发操作

search_tweets <- function(search) return(search)

library(shiny)
ui <- fluidPage( # Application title
#titlePanel("Twitter Analytics"), fluidRow(
column( 4, titlePanel("Twitter Analytics")),
column( 3, textOutput("mysearch") ),
column( 4, textInput("searchstring",
label = "",
value = "")),
column(1,
br(),
actionButton("action", "go")) )
) server <- function(input, output) { twitter <- eventReactive(input$action,{
search_tweets(input$searchstring)
}) output$mysearch <- renderText({
twitter()
})
} shinyApp(ui, server)

https://mlog.club/article/4593588

其他

shiny页面布局

observeEvent和eventReactive的区别

数据响应触发

需要系统性学习了,不然不能随心所欲,寸步难行。多看看别人的项目:

https://github.com/rli012/CancerMIRNome

https://github.com/wangshisheng/NAguideR

【R shiny】一些应用记录的更多相关文章

  1. Building [Security] Dashboards w/R & Shiny + shinydashboard(转)

    Jay & I cover dashboards in Chapter 10 of Data-Driven Security (the book) but have barely mentio ...

  2. R Shiny app | 交互式网页开发

    网页开发,尤其是交互式动态网页的开发,是有一定门槛的,如果你有一定的R基础,又不想过深的接触PHP和MySQL,那R的shiny就是一个不错的选择. 现在R shiny配合R在统计分析上的优势,可以做 ...

  3. R shiny 小工具Windows本地打包部署

    目录 服务器部署简介 windows打包部署 1. 部署基本框架 2.安装shiny脚本需要的依赖包 3.创建运行shiny的程序 [报错解决]无法定位程序输入点EXTPTE_PTR于动态链接库 将小 ...

  4. R︱shiny实现交互式界面布置与搭建(案例讲解+学习笔记)

    要学的东西太多,无笔记不能学~~ 欢迎关注公众号,一起分享学习笔记,记录每一颗"贝壳"~ --------------------------- 看了看往期的博客,这个话题竟然是第 ...

  5. kmeans聚类中的坑 基于R shiny 可交互的展示

    龙君蛋君 2015年5月24日 1.背景介绍 最近公司在用R 建模,老板要求用shiny 展示结果,建模的过程中用到诸如kmean聚类,时间序列分析等方法.由于之前看过一篇讨论kmenas聚类针对某一 ...

  6. 将Shiny APP搭建为独立的桌面可执行程序 - Deploying R shiny app as a standalone application

    目录 起源! 目的? 怎么做? 0 准备工作 1 下载安装R-portable 2 配置 Rstudio 3 搭建Shiny App 3.1 添加模块 3.2 写AppUI和AppServer 3.3 ...

  7. 使用R语言将微信记录制作成词云(简洁)--情人节奥义

    一.导出并读入微信聊天记录     参照百度的方法,使用同步助手.安装同步助手--连接手机(安卓苹果均可)--点击"其他功能"--点击微信图标即可进入聊天记录导出界面(非常简单). ...

  8. R 语言学习过程全记录 ~

    RStudio介绍超详细的教程:https://www.jianshu.com/p/132919ca2ca9 前辈的心得:https://blog.csdn.net/kMD8d5R/article/d ...

  9. SHINY-SERVER R(sparkR)语言web解决方案 架设shiny服务器

    1. shiny server简介 shiny-server是一种可用把R 语言以web形式展示的服务,其实RStudio公司自己构建了R Shiny Application运行的平台(http:// ...

随机推荐

  1. 第五次Alpha Scrum Meeting

    本次会议为Alpha阶段第五次Scrum Meeting会议 会议概要 会议时间:2021年4月30日 会议地点:线上会议 会议时长:15min 会议内容简介:本次会议以主要围绕卡牌对接的诸多问题与对 ...

  2. oo第三单元学习总结

    OO第三单元小结 一.JML语言理论基础及工具链梳理 在本单元我们学习了JML语言的一些基础知识,能够让我们看懂简单的JML规格并写出对应代码, 主要用到的知识点有:   1.requires 该子句 ...

  3. 第四单元博客总结——暨OO课程总结

    第四单元博客总结--暨OO课程总结 第四单元架构设计 第一次UML作业 简单陈述 第一次作业较为简单,只需要实现查询功能,并在查询的同时考虑到性能问题,即我简单的将每一次查询的结果以及递归的上层结果都 ...

  4. 2021.8.9考试总结[NOIP模拟34]

    T1 Merchant 如果$t=0$时不能达到$s$,那么所拿物品的价值一定关于时间单调递增,答案单调.因此可以特判$0$后二分. 用$sort$复杂度被卡,要用$\textit{nth_eleme ...

  5. 六个好习惯让你的PCB设计更优

    PCB layout工程师每天对着板子成千上万条走线,各种各样的封装,重复着拉线的工作,也许很多人会觉得是很枯燥无聊的工作内容.看似软件操作搬运工,其实设计人员在过程中要在各种设计规则之间做取舍,兼顾 ...

  6. NOIP 模拟 八十五

    T1 冲刺NOIP2021模拟18 莓良心 容易发现答案和每一个 \(w_i\) 无关,我们只需要求出总和然后计算方案数. 对于每一个数贡献的方案数是相同的,首先是自己的部分就是\(\begin{Bm ...

  7. Spring源码解读(二):Spring AOP

    一.AOP介绍 面向方面编程(AOP)通过提供另一种思考程序结构的方式来补充面向对象编程(OOP).OOP中模块化的关键单元是类,而在AOP中,模块化单元是方面.方面实现了诸如跨越多种类型和对象的事务 ...

  8. 负载均衡算法WRR介绍

    一.负载均衡 负载均衡是一个很大的概念,既有从硬件层面来解决问题的,又有从软件层面解决的,有关负载均衡的介绍,推荐阅读: http://os.51cto.com/art/201108/285359.h ...

  9. node 读取文件内容并响应

    node 读取文件内容并响应 const http = require('http'); const fs = require('fs') //创建 Server const server = htt ...

  10. Springboot+vue前后端分离项目,poi导出excel提供用户下载的解决方案

    因为我们做的是前后端分离项目 无法采用response.write直接将文件流写出 我们采用阿里云oss 进行保存 再返回的结果对象里面保存我们的文件地址 废话不多说,上代码 Springboot 第 ...