我想进行反应显示,根据选择的输入选择器的值显示不同数量的文本输出。因此,当用户按下“更新”视图按钮时,应执行新输出,同时前一个输出仍然可见...
{ "outputs" : [ { "var1" :... , "var2" :.... , "var3" :... , "var4" :.... , "height-weight" :[ 1000 , 500 ]},
{ "var1" :... , "var2" :.... , "var3" :... , "var4" :.... , "height-weight" :[ 12000 , 34]
,
{ "var1" :... , "var2" :.... , "var3" :... , "var4" :.... , "height-weight" :[ 12 , 50 ]
ui.R
library(shiny)
fluidPage(
sidebarLayout(
sidebarPanel(
numericInput("Caption","How many outputs you want to
make?",2,min=1,max=NaN) ,
textInput("var1", "var1:"),
textInput("var2", "var2:" ),
# Specification of range within an interval
sliderInput("height", "height:",
min = -500, max = 500, value = c(1000)),
sliderInput("weight", "weight:",
min = -500, max = 500, value = c(500)),
textInput("var3", "var3" ),
textInput("var4", "var4" ),
submitButton("Update View", icon("refresh"))
# actionButton("update", "Update")
),
mainPanel(
tableOutput("values"),
textOutput("text1")
)
)
)
server.R
function(input, output,session) {
# Show the values using an HTML table
output$values <- renderTable({
# sliderValues()
output$text1<- renderText({
paste("{","\"outputs\"",":","[",
"{","\"var1\"",":",input$var1,",",
"\"var2\"",":",input$var2,",",
"\"feature.attribute\"",":",input$var3,",",
"\"var3\"",":",input$var4,",",
"\"var4\"",":",input$var5,",",
"\"height-weight\"",":","[",input$height,",",input$weight,"]",""
)
})
答案 0 :(得分:0)
您希望用户输入各种值,在准备好后提交这些值,然后显示提交的值。以下代码并没有解决您的所有问题,但它应该让您开始:
library(shiny)
ui <- fluidPage(
mainPanel(
textInput("var1", "var1:"),
textInput("var2", "var2:" ),
# Specification of range within an interval
sliderInput("height", "height:",
min = -500, max = 500, value = c(1000)),
sliderInput("weight", "weight:",
min = -500, max = 500, value = c(500)),
textInput("var3", "var3:" ),
textInput("var4", "var4:" ),
actionButton("add", "Update View", icon("refresh")),
tableOutput("values")
))
server <- function(input, output,session) {
data <- reactiveValues()
data$df <- NA
observeEvent(input$add,
{ entry <- isolate( data.frame( var1 = input$var1,
var2 = input$var2,
var3 = input$var3,
var4 = input$var4,
height = input$height,
weight = input$weight ))
isolate(data$df <- rbind(data$df, entry)) })
output$values <- renderTable({ data$df })
}
shinyApp(ui=ui,server=server)
请注意以下命令
使用reactiveValues
在现有数据中添加新值。 data.frame
存储为reactiveValues
的元素。要仅在用户准备就绪时添加值,我使用actionButton
代替submitButton
。这可以在按下操作按钮时observeEvent
。通过isolate
执行对被动数据的操作。