- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这些数据
我想使用 R
shiny
scatter
plot
> 服务器:
library(dplyr)
library(permute)
set.seed(1)
meta.df <- data.frame(gene_id=paste0("id",1:10),symbol=paste0("n",rep(permute::shuffle(5),2)),stringsAsFactors=F)
clusters.df <- data.frame(cell=paste0("c",1:100),cluster=rep(permute::shuffle(10),10),sample=paste0("s",rep(permute::shuffle(5),20)),stringsAsFactors=F)
mat <- matrix(rnorm(10*100),10,100,dimnames=list(meta.df$gene_id,clusters.df$cell))
tsne.obj <- Rtsne::Rtsne(t(mat))
tsne.df <- as.data.frame(tsne.obj$Y) %>% dplyr::rename(tSNE1=V1,tSNE2=V2) %>% cbind(clusters.df)
samples <- c("all",unique(clusters.df$sample))
samples.choices <- 1:length(samples)
names(samples.choices) <- samples
因为我希望能够选择一个特定的 meta.df$symbol
,它在 meta.df$gene_id
中是多余的,所以每个都有一个选择列表,其中第二个以第一个为条件。
由于数据由多个 sample
组成,我希望能够以 react 方式通过 sample
对数据进行子集化,因此我有一个示例选择 checkbox
,使用 "all"
选项选择所有 sample
(只是因为它比选中所有框更容易)。
这是我的 Shiny
代码
:
server <- function(input, output)
{
chosen.samples <- reactive({
validate(
need(input$samples.choice != "",'Please choose at least one of the sample checkboxes')
)
samples.choice <- input$samples.choice
if("all" %in% samples.choice) samples.choice <- samples[-which(samples == "all")]
samples.choice
})
output$gene_id <- renderUI({
selectInput("gene_id", "Gene ID", choices = unique(dplyr::filter(meta.df,symbol == input$symbol)$gene_id))
})
scatter.plot <- reactive({
if(!is.null(input$symbol) & !is.null(input$gene_id)){
# subset of data
gene.symbol <- input$symbol
gene.id <- input$gene_id
row.idx <- which(rownames(mat) == gene.id)
col.idx <- which(colnames(mat) %in% dplyr::filter(clusters.df,sample %in% chosen.samples())$cell)
gene.df <- suppressWarnings(dplyr::left_join(tsne.df %>% dplyr::filter(sample %in% chosen.samples()),data.frame(cell=colnames(mat)[col.idx],value=mat[row.idx,col.idx],stringsAsFactors=F),by=c("cell"="cell")))
scatter.plot <- plotly::plot_ly(marker=list(size=12),type='scatter',mode="markers",color=~gene.df$value,x=~gene.df$tSNE1,y=~gene.df$tSNE2,showlegend=F) %>%
plotly::layout(xaxis=list(title="tSNE1",zeroline=F,showticklabels=F),yaxis=list(title="tSNE2",zeroline=F,showticklabels=F))
scatter.plot
}
})
output$Embedding <- renderPlot({
scatter.plot()
})
output$save <- downloadHandler(
filename = function() {
paste0(dplyr::filter(meta.df,symbol == input$symbol,gene_id == input$gene_id)$symbol,"_",dplyr::filter(meta.df,symbol == input$symbol,gene_id == input$gene_id)$gene_id,".pdf")
},
content = function(file) {
plotly::export(scatter.plot(),file=file)
}
)
}
ui <- fluidPage(
# App title ----
titlePanel("Results Explorer"),
# Sidebar layout with a input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
# select samples
checkboxGroupInput("samples.choice", "Samples",choices = samples.choices,selected=1),
# select gene symbol
selectInput("symbol", "Gene Symbol", choices = unique(meta.df$symbol)),
# select gene id
uiOutput("gene_id"),
# select plot type
selectInput("plot.type", "Plot Type", choices = c("tSNE","PCA")),
# save plot as html
downloadButton('save', 'Save as PDF')
),
# Main panel for displaying outputs ----
mainPanel(
# The plot is called Embedding and will be created in ShinyServer part
plotOutput("Embedding")
)
)
)
shinyApp(ui = ui, server = server)
问题是它似乎并没有真正选择 sample
,因此显示的图没有任何点。
如果我简单地通过替换来消除 sample
的选择 code
,它会起作用:
col.idx <- which(colnames(mat) %in% dplyr::filter(clusters.df,sample %in% chosen.samples())$cell)
gene.df <- suppressWarnings(dplyr::left_join(tsne.df %>% dplyr::filter(sample %in% chosen.samples()),data.frame(cell=colnames(mat)[col.idx],value=mat[row.idx,col.idx],stringsAsFactors=F),by=c("cell"="cell")))
与:
col.idx <- which(colnames(mat) %in% dplyr::filter(clusters.df,sample %in% samples[2:3])$cell)
gene.df <- dplyr::left_join(tsne.df %>% dplyr::filter(sample %in% samples[2:3]),data.frame(cell=colnames(mat)[col.idx],value=mat[row.idx,col.idx],stringsAsFactors=F),by=c("cell"="cell"))
我在 this example 中看到了整个数据在 dat_reac
reactive
block
中被子集化。我希望简单地将 sample
设置为子集 by 就足够了。知道为什么它不起作用以及如何让它正确吗?
最佳答案
您的代码中有两个错误。第一个在checkboxGroupInput
代替
checkboxGroupInput("samples.choice", "Samples",choices = samples.choices,selected=1)
应该是
checkboxGroupInput("samples.choice", "Samples",choices = names(samples.choices),selected="all")
第二个是scatter.plot()
是plotly object
因此你应该使用 plotly::plotlyOutput("Embedding")
和 output$Embedding <- plotly::renderPlotly({
scatter.plot()
})
这里是经过上述修改的代码应该可以工作:
server <- function(input, output)
{
chosen.samples <- reactive({
validate(
need(input$samples.choice != "",'Please choose at least one of the sample checkboxes')
)
samples.choice <- input$samples.choice
if("all" %in% samples.choice) samples.choice <- samples[-which(samples == "all")]
samples.choice
})
output$gene_id <- renderUI({
selectInput("gene_id", "Gene ID", choices = unique(dplyr::filter(meta.df,symbol == input$symbol)$gene_id))
})
scatter.plot <- reactive({
if(!is.null(input$symbol) & !is.null(input$gene_id)){
# subset of data
gene.symbol <- input$symbol
gene.id <- input$gene_id
row.idx <- which(rownames(mat) == gene.id)
col.idx <- which(colnames(mat) %in% dplyr::filter(clusters.df,sample %in% chosen.samples())$cell)
gene.df <- suppressWarnings(dplyr::left_join(tsne.df %>% dplyr::filter(sample %in% chosen.samples()),data.frame(cell=colnames(mat)[col.idx],value=mat[row.idx,col.idx],stringsAsFactors=F),by=c("cell"="cell")))
scatter.plot <- plotly::plot_ly(marker=list(size=12),type='scatter',mode="markers",color=~gene.df$value,x=~gene.df$tSNE1,y=~gene.df$tSNE2,showlegend=F) %>%
plotly::layout(xaxis=list(title="tSNE1",zeroline=F,showticklabels=F),yaxis=list(title="tSNE2",zeroline=F,showticklabels=F))
scatter.plot
}
})
output$Embedding <- plotly::renderPlotly({
scatter.plot()
})
output$save <- downloadHandler(
filename = function() {
paste0(dplyr::filter(meta.df,symbol == input$symbol,gene_id == input$gene_id)$symbol,"_",dplyr::filter(meta.df,symbol == input$symbol,gene_id == input$gene_id)$gene_id,".pdf")
},
content = function(file) {
plotly::export(scatter.plot(),file=file)
}
)
}
ui <- fluidPage(
# App title ----
titlePanel("Results Explorer"),
# Sidebar layout with a input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
# select samples
checkboxGroupInput("samples.choice", "Samples",choices = names(samples.choices),selected="all"),
# select gene symbol
selectInput("symbol", "Gene Symbol", choices = unique(meta.df$symbol)),
# select gene id
uiOutput("gene_id"),
# select plot type
selectInput("plot.type", "Plot Type", choices = c("tSNE","PCA")),
# save plot as html
downloadButton('save', 'Save as PDF')
),
# Main panel for displaying outputs ----
mainPanel(
# The plot is called Embedding and will be created in ShinyServer part
# plotOutput("Embedding")
plotly::plotlyOutput("Embedding")
)
)
)
shinyApp(ui = ui, server = server)
希望对您有所帮助!
关于r - 将 R shiny checkboxGroupInput 与其他输入选择相结合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50110300/
我正在通过 Rscript.exe 在托管到我的本地网络的服务器上运行 Shiny 应用程序。如果我们要将其移植到网上,我们可以通过我们设置的服务器基础设施来实现。 Shiny Server 是否添加
当我运行我的 Shiny 应用程序时,我的数据表的标题向左移动。见下文。 假设这张表在选项卡 A 上。 当我单击不同的选项卡(选项卡 B)时,标题会正确对齐,然后再次单击选项卡 A。有关更正的标题,请
是否有查询正在运行的 RStudio Shiny 网页以显示正在运行的服务器版本的变量或方法?例如。显示类似 shiny-0.10.1在网页上。 有任何想法吗? 最佳答案 您可以使用 packageV
我想在以下位置重现示例:https://scip.shinyapps.io/scip_app/ 基本上,我有一个 300 x 300 调整后的相关矩阵和一个 300 x 300 未调整的相关矩阵,我想
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 去年关闭。 社区去年审查了是否重
在我部署应用程序时,应用程序中仍然存在一些异常情况,因此我想将它们从我的帐户中删除。我试过了,但没有找到任何选择。任何帮助将不胜感激。谢谢 最佳答案 在从 shiny.io 填充 token 信息后,
据我了解,Shiny Server 的开源版本不支持身份验证。 我们有一个环境使用 WebSEAL 代理服务来验证用户并将他们的访问引导到 Web 应用程序。 我们希望向经过身份验证的用户公开 Shi
我想将一个 R 应用程序(在装有 OS RHEL6.8 的实际 Shiny 服务器上运行良好)转移到另一个"new" Shiny 服务器。我的应用程序在第一台服务器上运行良好。这个想法是将它放在性能更
我正在通过 #RMarkdown 创建一个测试页面并尝试在其中添加 #Shiny 内容。在编织到 HTML 时,我收到以下错误。 Error in appshot.shiny.appobj(list(
有没有一种简单的方法可以在 shiny 中创建这样的东西? 最佳答案 RStudio 目前正在处理 sortable 包:RStudio/sortable 请注意,它目前正在开发中(标记为实验性),因
当我在一个非常简单的 Shiny 应用程序中按下操作按钮时,我试图调用另一个 Shiny 的应用程序。另一个应用程序位于一个带有 ui.R 和 server.R 文件的名为 Benefits 的文件夹
我最近试图在我的服务器上打开一个 Shiny 的服务器应用程序,并遇到了我以前从未见过的错误。 Error in loadNamespace(j -c "R -e \"install.pack
我有 Shiny 的应用程序,它显示旧数据(延迟 4 天!),但服务器数据已刷新(当天)。 奇怪的是,服务器上不存在旧数据集 - 似乎只存在于 Shiny 缓存中。 在服务器上,我有 1 个数据集由
我有一个在本地 R 服务器(端口 8787)上运行的应用程序。当我将它移动到 Shiny Server(端口 3838)时,我收到消息 ERROR: An error has occurred. Ch
我试图消除此表格与浏览器窗口左侧之间的空间,但当我这样做时,它弄乱了导航栏链接和标题的间距。 如何在不改变 navbar/ui/li 元素的填充/边距的情况下删除 excelR 表上的填充/边距? l
我已经阅读并实现了来自 link 的 Shiny 表中的复选框.但是当我在 R 中运行时,列中的输出是 , 等在每个“选择”单元格中,我希望“选择”列中的输出是复选框,我的问题的解决方案是什么?谢谢
我一直在开发一个 Shiny 的应用程序,它开始变得相当大。 我通过将应用程序的不同部分放入各自文件中的模块中解决了这个问题,然后获取文件。 问题是,当我在源文件的服务器部分(下例中的 events.
我对 Shiny 和 DataTables 还很陌生,所以这可能是个愚蠢的问题。由于某种原因,我无法更改列宽。我试过了 output$table<-DT::renderDataTable( {w
我安装了我的 Shiny 服务器,它在这个目录下的多个应用程序上工作正常: /srv/ Shiny 服务器/app1/srv/ Shiny 服务器/app2 我可以使用 www.mydomain.co
我想在我的 Shiny 应用程序中包含我的 myMardown.md 文档。 为了显示目录,我使用了 toc 选项,还使用了 css (myStyle.css) myMarkdown.md : ---
我是一名优秀的程序员,十分优秀!