小编bsi*_*ieb的帖子

在调用依赖于 renderUI 的反应式函数之前,不会执行 renderUI

在我闪亮的应用程序中,我有两个选项卡:选项卡 1 有一个 checkboxInput 和一个 selectInput,它在 server.R 中编码为 renderUI,并且仅在选中该框时才显示。在突片2中,存在GGVIS功能,用于绘制通过在选项卡1中所示的选择input时通过反应函数进行的数据帧。

出乎意料的是,selectInput 没有显示在选项卡 1 中,除非我先单击选项卡 2 然后返回选项卡 1,即使 selectInput 仅依赖于同一选项卡中的复选框,即选项卡 1。

显然,我没有正确理解反应式函数的概念。你能指出我的错误在哪里吗?谢谢!

PS 结构相当复杂,但它是我的“真实”应用程序所需要的。

用户界面

library(ggvis)

shinyUI(navbarPage("",
                   tabPanel("1",
                              checkboxInput("START", label = "Start calculations", value = F),
                              htmlOutput("SELECT")
                   ),
                   tabPanel("2",
                            ggvisOutput("PLOT")
                   )
))
Run Code Online (Sandbox Code Playgroud)

服务器

library(ggvis)

shinyServer(function(input, output, session) {

  output$SELECT<-renderUI({ 
    if (input$START==T) {
    selectInput("SELECTINPUT","Make your choice:",c(1,2))
    }
  })

  PLOTDF<-reactive({
    if (is.null(input$SELECTINPUT)==F) {
      plotdf<-data.frame(c(1,1,2,2),c(1,2,3,4))
      colnames(plotdf)<-c("X","Y")
      plotdf
    }
  })

  reactive({
    PLOTDF() %>% ggvis(~X,~Y) %>% layer_points
    }) %>% bind_shiny("PLOT")

})
Run Code Online (Sandbox Code Playgroud)

r shiny ggvis

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

R闪亮:selectInput - javascript片段出现在UI中

目标是显示 selectInput 输入的列表。该列表显示正确,但在每个单独的输入菜单的名称旁边(本例中为“a”、“b”、“c”)显示以下字符串:“div form-groupshiny-input-container”。我非常感谢您提示为什么会发生这种情况!

截屏:

在此输入图像描述

ui.R

shinyUI(
  htmlOutput("tabs")
)
Run Code Online (Sandbox Code Playgroud)

服务器R

shinyServer(function(input, output, session) {

output$tabs<-renderUI({
    navbarPage("MyApp",tabPanel("Tab",htmlOutput("myoutput")))
})

output$myoutput<-renderUI({ 
  datavector<-c('one','two','three')  
  outputlist<-list()  
  for (i in 1:3) {
    output<-selectInput(paste("selection",i,sep=""), c('a','b','c')[i], 
                        c("one"=1,"two"=2,"three"=3),
                        selected=datavector[i])
    outputlist<-append(outputlist,output)
  }  
  outputlist
})
})
Run Code Online (Sandbox Code Playgroud)

提前致谢!

博格丹

r shiny

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

标签 统计

r ×2

shiny ×2

ggvis ×1