【发布时间】:2017-11-22 16:42:23
【问题描述】:
我已经编写了 R 代码并尝试创建一个闪亮的应用程序,该应用程序将用于与 gui 相同的目的。
R 代码:
text1 <-data.frame(x=2,y=30)
text1
text2 <- data.frame(a=11,b=10)
text2
# fisrt set of data
z<- cbind.data.frame(text1,text2)
z
# second set of data
nz <-cbind.data.frame(text1,text2)
nz
# combined data. my plan to change the z or nz, and it will reflect everytime, and save as z.
# every time I change any value of x,y,a,and b. it should add a new row
# couldn't able to write the following steps in shiny as reactive form
z <- rbind.data.frame(z,nz)
z
我试图准备一个闪亮的应用程序,但无法执行
的步骤z <- rbind.data.frame(z,nz)
z
在闪亮。任何人有任何想法都会有所帮助。 z 将被 z 和 nz 的行绑定覆盖。闪亮的应用程序代码如下:
library(shiny)
ui <- fluidPage(theme = shinytheme("sandstone"),
# header
headerPanel("DTI post analysis conversion"),
sidebarLayout(
# sidebar for form
sidebarPanel(
h3("Information",""),
textInput("x", "Value X",""),
textInput("y", "Value Y",""),
textInput("a", "Value a",""),
textInput("b", "Value b",""),
actionButton("update", "first data Set"),
actionButton("update1", "Add another Set")),
# output for viewing
mainPanel(
DT::dataTableOutput("tableDT"),
#DT::dataTableOutput("tableDT1"),
DT::dataTableOutput("tableDT2")
)
)
)
server <- function(input, output, session) {
text1 <- reactive({
tx1 <- data.frame(X = input$x,
Y = input$y)
})
text2 <- reactive({
tx2 <- data.frame(A = input$a,
B = input$b)
})
# create 1st row of data
z <- eventReactive(input$update,{
cbind.data.frame(text1(), text2())
})
# create 2nd row of data
nz <- eventReactive(input$update1,{
cbind.data.frame(text1(), text2())
})
# everytime I change any value and click "add another data set", it should add a new row
# the problem is it only works for the first time.
combine <- eventReactive(input$update1,{
rbind.data.frame(z(), nz())
})
output$tableDT <- DT::renderDataTable(
z()
)
output$tableDT1 <- DT::renderDataTable(
nz()
)
output$tableDT2 <- DT::renderDataTable(
combine()
)
}
shinyApp (ui = ui, server = server)
【问题讨论】:
-
我没有收到任何错误,当我按下添加另一行时,rbind 工作正常。能否请您详细说明一下这个问题?
-
@amrrs 感谢您的回复。如果我想添加多行,它没有添加。它仅适用于前两组。它应该通过插入 x、y、a、b 的值来添加尽可能多的行。我正计划构建一个闪亮的应用程序,它将添加您输入的每组值作为 x,y,a,b。
-
谢谢。我已经更新了多个 rbind 的答案。请检查。