使用 R闪亮,是否可以将 selectInput 项目链接到打开文件操作按钮?我想调整操作按钮的 onclick 参数来实现它。
请在下面找到一个可重现的示例:
假设“www”文件夹中有“file_1.pdf”和“file_2.pdf”,如何打开与选择输入选项相对应的文件?
library(shinydashboard)
library(shiny)
ui <- dashboardPage(
dashboardHeader(title = "Open file app"),
dashboardSidebar(),
dashboardBody(
fluidRow(
selectInput(inputId = "file_choice",label = "Choose the file to open",choices = c("file_1","file_2")),
actionButton("bell","Open the selected file", class = "btn action-button",onclick = "window.open('file_1.pdf')")) #onclick argument must be adapted
)
)
server <- function(input, output) {}
shinyApp(ui, server)
多谢!
你可以做
selectInput(inputId = "file_choice",
label = "Choose the file to open",
choices = c("file_1"="Rplot01.png","file_2"="Rplot02.png")),
actionButton("bell","Open the selected file", class = "btn action-button",
onclick = "window.open($('#file_choice').val())"))
解释: $(...)
是一个选择器。$('#file_choice')
选择具有 id 的元素file_choice
。这是selectInput
. And $('#file_choice').val()
返回所选选项的值。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)