首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Shiny: inFile更改的更新选择

Shiny: inFile更改的更新选择
EN

Stack Overflow用户
提问于 2015-10-11 18:42:53
回答 1查看 412关注 0票数 0

我希望在上传文件(fileInput)的依赖项中提供inputselect“选择”。在下面的示例中,我希望as.list(mydata[1, 1:5])作为inputselect选项的值。稍后,子设置值将是动态的,此处不显示。

我尝试了论坛上提出的几种方法(反应、观察、reactiveValue和它们的结合),但都没有成功。

我的脚本部分运行,但是我需要页面刷新来获取上传的“选项”,然后再重新加载文件。

server.R

代码语言:javascript
复制
shinyServer(function(input, output, session) {

output$contents <- renderDataTable({

    inFile <<- input$SoftRecom
    if (is.null(inFile))
        return(NULL)
    filedatapath <<- reactive({inFile$datapath})
    mydata <<- read.csv(filedatapath(), header = TRUE, sep = ',')
    mydata
})


mychoices <<- reactive({
    mydata
    print(mydata)
    })

output$vg <- renderUI({
    selectInput("vg", label =  p("goal", style = "color:#FFA500"), 
       mychoices()[1,1:5], selected = 1)
})   

output$vp <- renderUI({
    selectInput("procedure", label =  p("procedure", style = "color:#FFA500"), 
                choices = c("proecudures"), selected = 1)

})

output$vm <- renderUI({
    selectInput("procedure", label =  p("procedure", style = "color:#FFA500"), 
                choices = c("ChIP-seq"), selected = 1)

})
})

ui.R

代码语言:javascript
复制
shinyUI(fluidPage(theme = "bootstrap.css",
titlePanel("simple software recommendation sytem"),
sidebarLayout(
    sidebarPanel(
        fileInput('SoftRecom', 'choose dataset'),

        uiOutput("vg"), # variable goal 
        uiOutput("vp"), # variable procedure
        uiOutput("vm")  # variable method


    ),
    mainPanel(
        dataTableOutput('contents')
    )
)
))

我在论坛上看到了许多例子和答案,它们非常接近(甚至与我的问题相匹配)。抱歉,我这么迟钝。如果有人能告诉我这个问题,我会非常感激的。

杰伦

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-21 15:50:08

最后我自己找到了解决办法。不要对我的问题和答案中的不同服务器代码感到困惑。只要看一下

  • uiOutput(流水线步骤)和
  • 输出$pconst<- renderUI({selectizeInput( 'pconst',‘构造软件工作流’),as.character= as.character(mysoftmysoft$goal==mypipefilter,3),multiple = TRUE,options = list(maxItems =1)}}

UI.R

我不得不插入:uiOutput(“管道步骤”),参见第8行

代码语言:javascript
复制
shinyUI(fluidPage(theme = "bootstrap.css",
titlePanel( h2("simple software recommendation system", style = "color:#FFA500")),
    sidebarLayout(position = "left",
        sidebarPanel(width =3,
             # chose standard pipeline
             selectInput("selectpipe", "select standard pipeline:", choices = pipechoices),
             # software details
             *uiOutput("pipelinestep")*, # software per pipeline step,
             # construct software workflow based on selected pipeline step 
             uiOutput("pconst")
        ))))

server.R

从第5行到第7行。一旦检测到更改,“选择”将获得分配的新值。请参阅这里的文档:http://shiny.rstudio.com/articles/dynamic-ui.html

代码语言:javascript
复制
pipelinestepsoftInput <<- reactive({
    mypipefilter <- input$pipelinestep
    softperpipe <<- mysoft[mysoft$goal==mypipefilter ,c(1,3,5:7), drop = FALSE]
    ## provides software choices related to the pipeline step
    output$pconst <<- renderUI({selectizeInput(
        'pconst', 'construct software workflow', choices = as.character(mysoft[mysoft$goal==mypipefilter, 3]),
        multiple = TRUE, options = list(maxItems = 1))})
    ## input for outputDataTable
    softperpipe 
    })  
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33068729

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档