R文本输入类似于表格格式
我有两个问题: 1) 我想为几个看起来像表格的文本输入字段提供服务。我的解决方案还可以,但由于每个字段的标题,行与行之间的空间太大。如何缩短文本输入字段之间的距离 2) 输出应为data.frame,其中包括来自输入的数据。如何在“Output$contents”中使用输入数据创建data.frame 多谢各位 代码的简短摘录:R文本输入类似于表格格式,r,input,text,shiny,R,Input,Text,Shiny,我有两个问题: 1) 我想为几个看起来像表格的文本输入字段提供服务。我的解决方案还可以,但由于每个字段的标题,行与行之间的空间太大。如何缩短文本输入字段之间的距离 2) 输出应为data.frame,其中包括来自输入的数据。如何在“Output$contents”中使用输入数据创建data.frame 多谢各位 代码的简短摘录: ui <- fluidPage( # App title ---- titlePanel("Stochastische Cashflows"),
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)
###########################################################################################################
ui您可以使用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()
})
df您可以使用css设置应用程序的样式
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)