R:修改数据帧中的输出值
下面这个简单的闪亮应用程序显示了一个单词及其情感,它存储在名为R:修改数据帧中的输出值,r,shiny,shiny-reactivity,R,Shiny,Shiny Reactivity,下面这个简单的闪亮应用程序显示了一个单词及其情感,它存储在名为sent的R数据框中 library(shiny) sent <- data.frame(word=c('happy', 'sad', 'joy', 'upset'), sentiment=c('positive', 'negative', 'positive', 'negative'), stringsAsFactors = FALSE) ui
sent
的R数据框中
library(shiny)
sent <- data.frame(word=c('happy', 'sad', 'joy', 'upset'),
sentiment=c('positive', 'negative', 'positive', 'negative'),
stringsAsFactors = FALSE)
ui <- fluidPage(
numericInput(inputId = 'num', label='', value=1, min=1, max=nrow(sent)),
br(),
h4("Word:"),
textOutput('word'),
br(),
h4("Sentiment:"),
textOutput('sentiment')
)
server <- function(input, output){
output$word <- renderText({ sent$word[input$num] })
output$sentiment <- renderText({ sent$sentiment[input$num] })
}
shinyApp(ui=ui, server=server)
库(闪亮)
发送这应该可以做到
library(shiny)
sent <- data.frame(word=c('happy', 'sad', 'joy', 'upset'),
sentiment=c('positive', 'negative', 'positive', 'negative'),
stringsAsFactors = FALSE)
sent2 <- reactiveVal(sent)
i <- 1
i2 <- reactiveVal(i)
ui <- fluidPage(
uiOutput("wordSelect"),
br(),
h4("Word:"),
textOutput('word'),
br(),
h4("Sentiment:"),
textOutput('sentiment'),
br(),
uiOutput("change"),
actionButton("go","Change")
)
server <- function(input, output){
output$wordSelect <- renderUI({
selectizeInput(inputId = 'wrd', label='select word', choices=sent$word, selected=sent$word[i2()])
})
output$word <- renderText({ input$wrd })
output$sentiment <- renderText({ sent$sentiment[which(sent2()$word==input$wrd)] })
observeEvent(input$go, {
out <- sent
out$sentiment[which(sent$word==input$wrd)] <- input$newLabel
sent <<- out
sent2(out)
i <<- which(sent$word==input$wrd)+1
if(i > length(sent$word)) {
i <<- i - 1
}
i2(i)
})
output$change <- renderUI({
radioButtons("newLabel", label="Change value", choices=c('positive','negative'), sent$sentiment[which(sent2()$word==input$wrd)])
})
}
shinyApp(ui=ui, server=server)
库(闪亮)
在Shinny中发送look in/google onreactive
variables..您可以使用selectizeInput()
而不是numeriInput()
来下拉选择单词hanks@MKBakker-这很有效!还有一个请求:单击更改操作按钮
时,是否可以自动移动到下一个单词(发送的中的行)
?@Miguel立即更新了此选项!非常感谢。