Link R shiny selectInput item to open file actionButton
Link R shiny selectInput item to open file actionButton
使用 R shiny,是否可以link select输入项目打开文件操作按钮?我想修改动作按钮的 onclick 参数来实现它。
请在下面找到一个可重现的示例:
假设我们在"www"文件夹中有"file_1.pdf"和"file_2.pdf",如何打开select输入选项对应的文件?
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
。并且 $('#file_choice').val()
returns 所选选项的值。
使用 R shiny,是否可以link select输入项目打开文件操作按钮?我想修改动作按钮的 onclick 参数来实现它。
请在下面找到一个可重现的示例:
假设我们在"www"文件夹中有"file_1.pdf"和"file_2.pdf",如何打开select输入选项对应的文件?
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
。并且 $('#file_choice').val()
returns 所选选项的值。