R 动态选择输入错误
我从Rstudio Shining示例中学会了在我的Shining应用程序中使用dynamic select输入。看起来一切正常,但发生了一个错误。我做了很多测试,发现错误是由于服务器中使用了observe函数的动态选择输入。但我想不出如何修复它。任何帮助都将不胜感激。谢谢 为了节省空间,一些代码没有显示 服务器.RR 动态选择输入错误,r,shiny,R,Shiny,我从Rstudio Shining示例中学会了在我的Shining应用程序中使用dynamic select输入。看起来一切正常,但发生了一个错误。我做了很多测试,发现错误是由于服务器中使用了observe函数的动态选择输入。但我想不出如何修复它。任何帮助都将不胜感激。谢谢 为了节省空间,一些代码没有显示 服务器.R load("./data/genomicVar.RData") load("./data/geneInfo.RData") fetchInfoByMsu <- functi
load("./data/genomicVar.RData")
load("./data/geneInfo.RData")
fetchInfoByMsu <- function(locus="") {...}
fetchSnpByMsu <- function(locus="") {...}
fetchIndelByMsu <- function(locus="") {...}
fetchSvByMsu <- function(locus="") {...}
fetchExpByMsu <- function(locus="") {...}
fetchInfoByBin <- function(binNumber="") {...}
fetchGeneByBin <- function(binNumber="") {...}
shinyServer(function(input, output, session) {
output$mytable1 = renderDataTable({...})
output$mytable2 = renderDataTable({...})
output$mytable3 = renderDataTable({...})
output$mytable4 = renderDataTable({...})
output$mytable5 = renderDataTable({...})
output$mytable6 = renderDataTable({...})
output$mytable7 = renderDataTable({...})
observe({
c_bin <- input$bin
c_gene <- fetchGeneByBin(input$bin)
c_gene <- c_gene$locus
# Select input
s_options <- list()
for (i in c_gene) {
s_options[[i]] <- i
}
# Change values for input$inSelect
updateSelectInput(session, "inSelect",
choices = s_options,
selected = c_gene[1]
)
})
output$mytable8 = renderDataTable({...})
output$mytable9 = renderDataTable({...})
output$mytable10 = renderDataTable({...})
output$mytable11 = renderDataTable({...})
output$mytable12 = renderDataTable({...})
})
用户界面
我更喜欢使用uiOutput进行动态输入,请参见以下示例:
用户界面
服务器.R
load("./data/genomicVar.RData")
load("./data/geneInfo.RData")
fetchInfoByMsu <- function(locus="") {...}
fetchSnpByMsu <- function(locus="") {...}
fetchIndelByMsu <- function(locus="") {...}
fetchSvByMsu <- function(locus="") {...}
fetchExpByMsu <- function(locus="") {...}
fetchInfoByBin <- function(binNumber="") {...}
fetchGeneByBin <- function(binNumber="") {...}
shinyServer(function(input, output, session) {
output$mytable1 = renderDataTable({...})
output$mytable2 = renderDataTable({...})
output$mytable3 = renderDataTable({...})
output$mytable4 = renderDataTable({...})
output$mytable5 = renderDataTable({...})
output$mytable6 = renderDataTable({...})
output$mytable7 = renderDataTable({...})
observe({
c_bin <- input$bin
c_gene <- fetchGeneByBin(input$bin)
c_gene <- c_gene$locus
# Select input
s_options <- list()
for (i in c_gene) {
s_options[[i]] <- i
}
# Change values for input$inSelect
updateSelectInput(session, "inSelect",
choices = s_options,
selected = c_gene[1]
)
})
output$mytable8 = renderDataTable({...})
output$mytable9 = renderDataTable({...})
output$mytable10 = renderDataTable({...})
output$mytable11 = renderDataTable({...})
output$mytable12 = renderDataTable({...})
})
尝试将s_选项设置为反应式表达式。错误消息是什么?另外,尝试使用uiOutput?我错了。错误不是由观察功能引起的。一些函数fetchInfoByMsu等返回了一些输入数据的零行数据帧。无论如何,谢谢你。UID输出非常好,而且简单得多。
shinyUI(fluidPage(
fluidRow(
absolutePanel(
#select bin
textInput("bin", label = h4("Bin ID:"), value = 1),
#dynamic options based on selected bin
uiOutput("inSelect")
)
)
)
)
shinyServer(function(input, output, session){
#genes dataframe
df <- data.frame(bin=c(1,1,1,2,2,2),
gene=c(12,13,14,21,23,24))
#dynamic select
output$inSelect <- renderUI({
selectInput("inSelect", strong("Select gene:"),
choices = df[ df$bin==input$bin,"gene"])
})
})