【问题标题】:R Shiny textInput like table formatR Shiny textInput 像表格格式
【发布时间】:2018-07-20 13:09:48
【问题描述】:

我有两个问题:

1) 我想提供几个看起来像表格的文本输入字段。我的解决方案没问题,但是由于每个字段所需的标题,行之间的空间太大。如何缩短文本输入字段之间的距离?

2) 输出应为包含来自输​​入的数据的 data.frame。如何使用“Output$contents”中的输入数据创建 data.frame?

谢谢。

代码摘录:

ui <- fluidPage(



# App title ----
  titlePanel("Stochastische Cashflows"),

  # Sidebar layout with input and output definitions ----
  sidebarLayout(


# Sidebar panel for inputs ----
sidebarPanel(

  h4("Psychologisch motivierte Abflüsse aus Einlagen"),
  tags$hr(),

  fluidRow(

    column(6,

           textInput("file1", "Passive Bilanzpostionen eingeben"),
           textInput("file2", "")
    ),

    column(6,

           textInput("file3", "Passive Bilanzpostionen eingeben"),
           textInput("file4", "")
    )
  ),



),

# Main panel for displaying outputs ----
mainPanel(

  # Output: Data file ----
  tableOutput("contents"),


)



 )
)


################################################################################################################

################################################################################################################

server <- function(input, output) {


  output$contents <- renderTable({

   print(9)


  })



################################################################################################################
################################################################################################################

# Create Shiny app ----
shinyApp(ui, server)

###########################################################################################################

【问题讨论】:

  • 您可以使用 css 为您的应用程序设置样式

标签: r input text shiny


【解决方案1】:

您可以使用 css 来减少上边距:

tags$style(type="text/css", "#file2 { margin-top: -20px }")

您可以在创建文本输入后立即放置。

要将内容作为数据框获取,反应式导体很好:

  df <- reactive({
    data.frame(A=c(input$file1, input$file2), B=c(input$file3, input$file4))
  })

  output$contents <- renderTable({
    df()
  })

完整代码:

library(shiny)

ui <- fluidPage(
  # App title ----
  titlePanel("Stochastische Cashflows"),
  # Sidebar layout with input and output definitions ----
  sidebarLayout(
    # Sidebar panel for inputs ----
    sidebarPanel(
      h4("Psychologisch motivierte Abflüsse aus Einlagen"),
      tags$hr(),
      fluidRow(
        column(6,
               textInput("file1", "Passive Bilanzpostionen eingeben"),
               textInput("file2", ""),
               tags$style(type="text/css", "#file2 { margin-top: -20px }")
        ),
        column(6,
               textInput("file3", "Passive Bilanzpostionen eingeben"),
               textInput("file4", ""),
               tags$style(type="text/css", "#file4 { margin-top: -20px }")
        )
      )
    ),
    # Main panel for displaying outputs ----
    mainPanel(
      # Output: Data file ----
      tableOutput("contents")
    )
  )
)

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

  df <- reactive({
    data.frame(A=c(input$file1, input$file2), B=c(input$file3, input$file4))
  })

  output$contents <- renderTable({
    df()
  })

}

# Create Shiny app ----
shinyApp(ui, server)

【讨论】:

    猜你喜欢
    • 2021-12-13
    • 2018-02-23
    • 1970-01-01
    • 2018-06-03
    • 1970-01-01
    • 1970-01-01
    • 2020-10-28
    • 2021-03-07
    • 1970-01-01
    相关资源
    最近更新 更多