R 使用输入数据更新变量
我试图在当前情况下,当用户按下按钮input$goButton中的一个操作按钮时,将当前情况下输入$n中的一个值附加到当前情况下的一个列表变量关键字列表中 这个怎么样:R 使用输入数据更新变量,r,variables,shiny,R,Variables,Shiny,我试图在当前情况下,当用户按下按钮input$goButton中的一个操作按钮时,将当前情况下输入$n中的一个值附加到当前情况下的一个列表变量关键字列表中 这个怎么样: library(shiny) ui <- pageWithSidebar( headerPanel("actionButton test"), sidebarPanel( #numericInput("n", "N:", min = 0, max = 100, value = 50), textI
library(shiny)
ui <- pageWithSidebar(
headerPanel("actionButton test"),
sidebarPanel(
#numericInput("n", "N:", min = 0, max = 100, value = 50),
textInput("n", "Caption", "Enter next keyword"),
br(),
actionButton("goButton", "Go!"),
p("Click the button to update the value displayed in the main panel.")
),
mainPanel(
verbatimTextOutput("nText"),
dataTableOutput('mytable')
)
)
})
library(shiny)
# Define server logic required to summarize and view the selected
# dataset
server <- function(input, output,session) {
global <- reactiveValues(keyword_list = "")
observe({
if (input$goButton == 0)
return()
isolate({
global$keyword_list <- append(global$keyword_list, input$n)
})
})
ntext <- eventReactive(input$goButton, {
input$n
})
output$nText <- renderPrint({
#input$n
ntext()
})
output$mytable = renderDataTable({
as.data.frame(global$keyword_list)
})
}
shinyApp(ui, server)
我也会使用reactiveValues,但是如果input$goButton==0返回,我会使用reqinput$goButton!=0:老实说,我也不是这部分的粉丝,但我更喜欢尽可能地修改原始代码,只回答实际问题。嗨,两种解决方案都很好!非常感谢你。现在我可以安心去滑雪了。祝您今天过得愉快。
library(shiny)
ui <- pageWithSidebar(
headerPanel("actionButton test"),
sidebarPanel(
#numericInput("n", "N:", min = 0, max = 100, value = 50),
textInput("n", "Caption", "Enter next keyword"),
br(),
actionButton("goButton", "Go!"),
p("Click the button to update the value displayed in the main panel.")
),
mainPanel(
verbatimTextOutput("nText"),
dataTableOutput('mytable')
)
)
})
library(shiny)
# Define server logic required to summarize and view the selected
# dataset
server <- function(input, output,session) {
global <- reactiveValues(keyword_list = "")
observe({
if (input$goButton == 0)
return()
isolate({
global$keyword_list <- append(global$keyword_list, input$n)
})
})
ntext <- eventReactive(input$goButton, {
input$n
})
output$nText <- renderPrint({
#input$n
ntext()
})
output$mytable = renderDataTable({
as.data.frame(global$keyword_list)
})
}
shinyApp(ui, server)