【问题标题】:R shiny error while rendering textinput for DT output为 DT 输出渲染文本输入时出现 R 闪亮错误
【发布时间】:2020-06-12 09:52:02
【问题描述】:

在我闪亮的应用程序中为 DT 渲染文本输入时,我遇到了一些非常奇怪的问题。 textinput 存储一些值,用作应用程序的设置之一。这些设置存储在响应式列表中,其中一个列表成员是 data.table - 存储所有渲染设置。

我做了一个可重现的例子,而不是代码 sn-ps。不漂亮,但它说明了。

library(shiny)

rv = reactiveValues()


ui <- shinyUI(fluidPage(

      textInput(inputId = "textinput", label = h3("Numeric input"), value = "some value"),
      tags$hr(),
      fluidRow(column(3, verbatimTextOutput("textinput"))),
      tags$hr(),
      tabPanel("Settings table for viewing", dataTableOutput('settings_table')),

))

server <- function(input, output, session) {
  observe({

    # lst_names = list()
    # lst_values = list()


    rv$textinput <-  renderText( input$textinput )
    output$textinput <- renderText({ input$textinput }) # this is displayed nicely

    # lst_names = c(lst_names, "rv$textinput") 
    # lst_values = c(lst_values, rv$textinput)        


    rv$settings = data.table(Var_names = "rv$textinput", Var_values = rv$textinput)

    })

  output$settings_table = DT::renderDataTable(options = list(pageLength = 50), {
    rv$settings
  })
}

shinyApp(ui, server)

我在 DT 的 github 中找到了这段文字,但我无法找到让它工作的方法。 与 numericinput、rendertext、renderprint、将 rendertext/print 移出“观察”块相同的问题。

有什么建议吗?

【问题讨论】:

  • reproducible example帮助你会更容易
  • 为什么"rv$textinput" 在引号中?
  • @bretauv:已添加。 Pork Chop:它是设置的名称,旁边有值。

标签: r shiny dt textinput


【解决方案1】:

你没有使用好的dataTableOutput。您必须使用 DT::dataTableOutput 或等价的 DT::DTOutput

library(shiny)
library(DT)

ui <- fluidPage(

  textInput(inputId = "textinput", label = h3("Numeric input"), 
            value = "some value"),
  tags$hr(),
  fluidRow(column(3, verbatimTextOutput("textinput"))),
  tags$hr(),
  tabPanel("Settings table for viewing", DTOutput('settings_table')),

)

server <- function(input, output, session) {

  output$textinput <- renderText({ input$textinput }) 

  rv <- reactiveValues()

  observe({

    rv$textinput <- input$textinput

    rv$settings <- data.frame(
      Var_names = "rv$textinput", 
      Var_values = rv$textinput
    )

  })

  output$settings_table <- renderDT(options = list(pageLength = 50), {
    rv$settings
  })

}

shinyApp(ui, server)

【讨论】:

    猜你喜欢
    • 2020-02-03
    • 1970-01-01
    • 1970-01-01
    • 2021-02-24
    • 1970-01-01
    • 2013-03-06
    • 2018-05-13
    • 2015-10-19
    • 1970-01-01
    相关资源
    最近更新 更多