我有下面的shiny
应用程序,当用户上传一个EXCEL文件时,会显示selectInput()
及其列名,还会显示一个指向已部署的shiny
应用程序的URL.
这个部署了shiny
的应用程序现在部署了data<-iris
和y<-Petal.Length
,但我想做的是将上传的文件作为data
传递给它,并将选定的列名作为y
.然后它将工作(没有问题与此)
我怎样才能做到这一点?我知道也许一个选项可以使用API,另一个选项可以使用pins
包,但我不确定如何做到这一点.当然,我对其他解决方案持开放态度.
initial app个
# Install and load necessary packages
library(shiny)
library(pins)
# Define the UI
ui <- fluidPage(
titlePanel("Shiny App with Link"),
column(3, fileInput("file1", "Upload File", multiple = FALSE, accept = c(".csv", ".xlsx", ".xls"))),
uiOutput("select"),
uiOutput("tab"),
)
# Define the server
server <- function(input, output,session) {
url <- a("Shinyapp", href="https://deniz4shinyml.shinyapps.io/iris/")
output$tab <- renderUI({
req(input$file1)
tagList("URL link:", url)
})
file_info <- reactive({
req(input$file1)
"xlsx" = readxl::read_excel(input$file1$datapath)
})
#####pins######
board_rsc <- pins::board_connect()
board_rsc %>% pin_write(file_info())
######pins#####
output$select<-renderUI({
req(input$file1)
selectInput("sel","select one column",choices = unique(colnames(file_info())),
selected = unique(colnames(file_info()))[1],
multiple = F)
})
}
# Run the app
shinyApp(ui, server)
deployed app个
# Load required libraries
library(shiny)
library(ggplot2)
library(pins)
# Load Iris dataset
data<-iris
y<-"Petal.Length"
######pin section
#data<-pin_read(board_rsc)
#y=?
########
# Define the UI for the Shiny app
ui <- fluidPage(
titlePanel("Iris Sepal Scatterplot"),
sidebarLayout(
sidebarPanel(
),
mainPanel(
plotOutput("scatterplot")
)
)
)
# Define the server logic for the Shiny app
server <- function(input, output) {
output$scatterplot <- renderPlot({
ggplot(data, aes(x = Sepal.Length, y = data[[y]])) +
geom_point()
})
}
# Run the Shiny app
shinyApp(ui, server)