可以使用shinysky在动态变化的数据帧上实现预先输入吗?

时间:2016-03-31 01:26:11

标签: shiny typeahead shinysky

我正在尝试使用R中的ShinySky软件包填充Shiny中的Typeahead盒子。

我试图扩展the example,其中用于预填充Typeahead的数据被硬编码到textInput.typeahead函数中:

textInput.typeahead(
        id="thti"
        ,placeholder="type 'name' or '2'"
        ,local=data.frame(name=c("name1","name2"),info=c("info1","info2")) #<- LOOK!
        ,valueKey = "name"
        ,tokens=c(1,2)
        ,template = HTML("<p class='repo-language'>{{info}}</p> <p class='repo-name'>{{name}}</p> <p class='repo-description'>You need to learn more CSS to customize this further</p>")
      )

在函数中间定义了一个本地数据帧并不是我想做的,正如这里的例子所做的那样:

,local=data.frame(name=c("name1","name2"),info=c("info1","info2")) 

我想向local提供一个参数,它是一个反应对象,它是在Shiny的其他地方创建的。

到目前为止,我还是无法这样做。

这是我尝试使用反应性动态填充Lookhead选项的策略:

1)让用户使用滑块对数据帧进行子集化 2)设置Lookahead以使用类似,local=subset(DF)的内容读入子集化数据帧  3)希望Lookahead的工作正常。

看起来够简单?这是一个屏幕截图,您可以清楚地看到Lookhead没有出现在111的用户输入下面。以下是我的代码。任何帮助将不胜感激。

enter image description here

library(shiny)
library(shinysky)
options(shiny.trace = F)  # change to T for trace

DF <- data.frame(ID=c("111", "222", "333", "444"), info=c("info1", "info2", "info3", "info4"))

runApp(list(ui = pageWithSidebar(
  headerPanel("This is a test"),
  sidebarPanel(
    helpText("I couldn't live without StackOverflow"),

    sliderInput("range",
                label = "Pick how many rows you want in your dataframe:",
                min = 2, max = 4, value = 2, step=1),

    helpText("After subsetting the dataframe using the controls above, can we make the Lookahead work?"),

    textInput.typeahead(
      id="thti"
      ,placeholder="type ID and info"
      ,local=subset(DF)
      ,valueKey = "ID"
      ,tokens=c(1,2)
      ,template = HTML("<p class='repo-language'>{{info}}</p> <p class='repo-name'>{{ID}}</p> <p class='repo-description'></p>"))

  ),
  mainPanel(textOutput("text1"),
            htmlOutput("text"),
            tableOutput('table')
  )
),
server = function(input, output, session) {

  subsetDF <- reactive({ DF <- DF[1:input$range, ]
                         DF
                         })

  output$text <- renderUI({
    str <- paste("This is how many rows you've chosen for your dataframe:",
                 input$range)
    HTML(paste(str, sep = '<br/>'))
                          })

  output$table <- renderTable(subsetDF())

}
)
)

0 个答案:

没有答案