渲染“;textInput";在R中按下浏览按钮后自动执行
我正在开发Rshinny,其中包括一个浏览按钮。我想要的是在我使用浏览按钮上传任何文件后,将“研究信息:”自动更改为“研究总结计算”。如何在R中实现这一点 我在下面包含了一段代码,我希望自动呈现文本渲染“;textInput";在R中按下浏览按钮后自动执行,r,shiny,R,Shiny,我正在开发Rshinny,其中包括一个浏览按钮。我想要的是在我使用浏览按钮上传任何文件后,将“研究信息:”自动更改为“研究总结计算”。如何在R中实现这一点 我在下面包含了一段代码,我希望自动呈现文本 textInput("txt", "Study info:", ""), 完整代码: ## Only run examples in interactive R sessions if (interactive()) { ui
textInput("txt", "Study info:", ""),
完整代码:
## Only run examples in interactive R sessions
if (interactive()) {
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
fileInput("file1", "Choose CSV File", accept = ".csv"),
textInput("txt", "Study info:", ""),
),
mainPanel(
tableOutput("contents")
)
)
)
server <- function(input, output) {
output$contents <- renderTable({
file <- input$file1
ext <- tools::file_ext(file$datapath)
req(file)
validate(need(ext == "csv", "Please upload a csv file"))
read.csv(file$datapath, header = input$header)
})
}
shinyApp(ui, server)
}
##仅在交互式R会话中运行示例
if(interactive()){
ui在更改input$file1
后,可以使用observeEvent
触发对updateTextInput
的调用
请检查以下内容:
library(shiny)
## Only run examples in interactive R sessions
if (interactive()) {
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
fileInput("file1", "Choose CSV File", accept = ".csv"),
textInput("txt", "Study info:", ""),
),
mainPanel(
tableOutput("contents")
)
)
)
server <- function(input, output, session) {
output$contents <- renderTable({
file <- input$file1
ext <- tools::file_ext(file$datapath)
req(file)
validate(need(ext == "csv", "Please upload a csv file"))
read.csv(file$datapath, header = input$header)
})
observeEvent(input$file1, {
updateTextInput(inputId = "txt", value = "Study Summary Calculations")
})
}
shinyApp(ui, server)
}
库(闪亮)
##仅在交互式R会话中运行示例
if(interactive()){
ui您是否可以在文本字段中显示文本“研究总结计算”,而不是作为标签?@ismirsehregal,有什么建议吗?请检查我的编辑。是的,它可以工作。