首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不适用于动态服务器UI的闪亮的shinyjqui

不适用于动态服务器UI的闪亮的shinyjqui
EN

Stack Overflow用户
提问于 2018-06-16 15:36:27
回答 1查看 214关注 0票数 0

我正在使用shinyjqui包,并且相信下面的代码应该创建可拖放的UI/绘图。但是,在使用Add UI按钮添加2+更多情节之后,返回的对象是不可拖放的。但是,当我使整个输出main_output可拖动时,我可以让它工作,但这不是我想要的。

有什么建议吗?

最起码的例子如下:

代码语言:javascript
复制
library(shinyjqui)

ui <- fluidPage(
    fluidRow(
        verticalLayout(
            uiOutput('main_output')
        )
    )
)
server <- function(input, output, session) {

    output$main_output <- renderUI({
        uiOutput('moduel_box')
    })

    render_moduels <- reactiveValues(input_types = NULL)

    observeEvent(input$add, {

        plot_type <- as.character(input$select)

        input_types <- render_moduels$input_types

        render_types <- unique(c(input_types, plot_type))

        render_moduels$input_types <- render_types

        output_types <<- c(render_moduels$input_types, 'moduel_box')

        output$main_output <- renderUI({

            lapply(output_types, uiOutput)

        })

        jqui_draggabled(paste0('#', output_types, sep=',', collapse = ''))

    })

    # jqui_draggable('#main_output') #This works though?

    output$moduel_box <- renderUI({
        box(width = '100%', 
            actionButton("add", "Add UI"),
            selectInput('select', 'please select', choices = c('histogram', 'line_plot'))
        )
    })
    output$histogram <- renderUI({

        box(
            renderPlot(hist(iris$Sepal.Length,30)),
            actionButton('rmv', 'remove')
        )
    })

    output$line_plot <- renderUI({

        box(
            renderPlot(plot(iris$Sepal.Length, type='l')),
            actionButton('rmv', 'remove')
        )
    })


}

shinyApp(ui, server)
EN

回答 1

Stack Overflow用户

发布于 2018-07-08 11:16:46

多个元素的选择器应该是"#id1,#id2"格式,而不是"#id1,#id2,"格式,因此jqui_draggabled的表达式应该改为jqui_draggabled(paste0('#', output_types, sep='', collapse = ','))

为了使动态UI的逻辑更加清晰,我建议在这里使用shiny::insertUI

代码语言:javascript
复制
observeEvent(input$add, {    
  plot_type <- as.character(input$select)    
  input_types <- render_moduels$input_types    
  if (plot_type %in% input_types) return()
  render_moduels$input_types <- c(input_types, plot_type)
  insertUI(
    selector = "#moduel_box",
    where    = "beforeBegin",
    ui       = jqui_draggabled(uiOutput(plot_type))
  )
})

而且,顺便说一句,box函数来自shinydashboard包,您应该在开始时加载它。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50889278

复制
相关文章

相似问题

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